Hey guys,
I was wondering: If I don't specify a namespace, what is the default namespace called of my class?
↧
What is the default namespace
↧
Can't Access NavMeshAgent methods
I am trying to use the UnityEngine.AI namespace and can't get any access to agent.speed or agent.destination
I have the proper namespace referenced, and for the life of me can't figure out what is going on. Has anyone else had this issue? Any ideas?
↧
↧
Serializing Properties (JSON saving and loading system)
Hello, I have a few scripts: https://pastebin.com/5fVjYpWN and I'm trying to save and load some things (floats, ints, and something Called BigDouble which is made up of 2 properties, mantissa and exponent in the BreakInfinity namespace used in the scripts). Everything saves and loads except for BigDoubles since it's not serializable, I tried adding the attribute in the namespace but that wouldn't work either. Any ways to do this? Thanks.
↧
2 error messages i can't seem to fix (CS0101 and CS0111)
My game worked just a few minutes ago, and now all these error messages pops up. I can't solve the issue because i just started with Unity and coding today.
**Error message 1:**
Assets\Scripts\PlayerMovement.cs(3,14): error CS0101: The namespace '' already contains a definition for 'PlayerMovement'
**Error message 2:**
Assets\Scripts\PlayerMovement.cs(13,10): error CS0111: Type 'PlayerMovement' already defines a member called 'FixedUpdate' with the same parameter types
![alt text][1]
[1]: https://cdn.discordapp.com/attachments/569967659647500297/597581493891760148/code.PNG
↧
How do i import the codeDOM (dynamic class generation) api by Microsoft
I want to create some editor tools that will dynamically generate classes for me, to help speed up workflows.
The api to use come from the the codeDOM and Microsoft.CSharp namespaces. But the editor doesn't recognize the Microsoft.CSharp namespace, nor does it recognize the codeDOM api's. What am i missing here?
Here's an idea about the api in use from the dot net documentation [link text][1]:
using System;
using System.CodeDom;
using System.CodeDom.Compiler;
using System.Collections;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
using Microsoft.CSharp;
using Microsoft.VisualBasic;
using Microsoft.JScript;
// This example demonstrates building a Hello World program graph
// using System.CodeDom elements. It calls code generator and
// code compiler methods to build the program using CSharp, VB, or
// JScript. A Windows Forms interface is included. Note: Code
// must be compiled and linked with the Microsoft.JScript assembly.
namespace CodeDOMExample
{
class CodeDomExample
{
// Build a Hello World program graph using
// System.CodeDom types.
public static CodeCompileUnit BuildHelloWorldGraph()
{
// Create a new CodeCompileUnit to contain
// the program graph.
CodeCompileUnit compileUnit = new CodeCompileUnit();
// Declare a new namespace called Samples.
CodeNamespace samples = new CodeNamespace("Samples");
// Add the new namespace to the compile unit.
compileUnit.Namespaces.Add(samples);
// Add the new namespace import for the System namespace.
samples.Imports.Add(new CodeNamespaceImport("System"));
// Declare a new type called Class1.
CodeTypeDeclaration class1 = new CodeTypeDeclaration("Class1");
// Add the new type to the namespace type collection.
samples.Types.Add(class1);
// Declare a new code entry point method.
CodeEntryPointMethod start = new CodeEntryPointMethod();
// Create a type reference for the System.Console class.
CodeTypeReferenceExpression csSystemConsoleType = new CodeTypeReferenceExpression("System.Console");
// Build a Console.WriteLine statement.
CodeMethodInvokeExpression cs1 = new CodeMethodInvokeExpression(
csSystemConsoleType, "WriteLine",
new CodePrimitiveExpression("Hello World!"));
// Add the WriteLine call to the statement collection.
start.Statements.Add(cs1);
// Build another Console.WriteLine statement.
CodeMethodInvokeExpression cs2 = new CodeMethodInvokeExpression(
csSystemConsoleType, "WriteLine",
new CodePrimitiveExpression("Press the Enter key to continue."));
// Add the WriteLine call to the statement collection.
start.Statements.Add(cs2);
// Build a call to System.Console.ReadLine.
CodeMethodInvokeExpression csReadLine = new CodeMethodInvokeExpression(
csSystemConsoleType, "ReadLine");
// Add the ReadLine statement.
start.Statements.Add(csReadLine);
// Add the code entry point method to
// the Members collection of the type.
class1.Members.Add(start);
return compileUnit;
}
public static void GenerateCode(CodeDomProvider provider,
CodeCompileUnit compileunit)
{
// Build the source file name with the appropriate
// language extension.
String sourceFile;
if (provider.FileExtension[0] == '.')
{
sourceFile = "TestGraph" + provider.FileExtension;
}
else
{
sourceFile = "TestGraph." + provider.FileExtension;
}
// Create an IndentedTextWriter, constructed with
// a StreamWriter to the source file.
IndentedTextWriter tw = new IndentedTextWriter(
new StreamWriter(sourceFile, false), " ");
// Generate source code using the code generator.
provider.GenerateCodeFromCompileUnit(
compileunit, tw, new CodeGeneratorOptions());
// Close the output file.
tw.Close();
}
public static CompilerResults CompileCode(CodeDomProvider provider, String sourceFile, String exeFile)
{
// Configure a CompilerParameters that links System.dll
// and produces the specified executable file.
String[] referenceAssemblies = { "System.dll" };
CompilerParameters cp =
new CompilerParameters(referenceAssemblies, exeFile,false);
// Generate an executable rather than a DLL file.
cp.GenerateExecutable = true;
// Invoke compilation.
CompilerResults cr = provider.CompileAssemblyFromFile(cp, sourceFile);
// Return the results of compilation.
return cr;
}
}
[1]: https://docs.microsoft.com/en-us/dotnet/api/system.codedom.compiler.codedomprovider?view=netframework-4.8
↧
↧
Can't access my script from a namespace
I am trying to access another component within the FirstPersonController script on my player character.
This script is inside its own UnityStandardAssets.Characters.FirstPerson namespace, which is why I think that when I use GetComponent to try to access the other script from another object, it simply says,
"The type or namespace xxx could not be found."
None of my other scripts are inside a namespace, so I can't use the 'using' keyword.
Is there a way to fix this (aside from taking the L and putting everything inside a namespace)? It seems strange that it won't let me access my scripts from the FirstPersonController.
Thanks in advance.
↧
using sinemachine.utility / using tmpro. error and problems.
hello all, my problem:
i used cinemachine and setup a cinemachine brain and cinemachine virtual camera, along a target group, everything worked fine until i updated unity.
now this was some time ago (1-2 months), after that the camera (text mesh pro to) keep working but i couldnt acces the namespace (using cinemachine/using tmpro) and if i went into the script it just showed a red line under it, and the code that i made (variables for example).
so i tryid to fix it today, searched google and the forums, updated unity today, deleted cinemachine and tmpro and installed again, nothing worked, same problem, the camera still works, tmpro still works, but i cant acces anything in a script.
btw im using (in case it helps):
visual studio 2017, version 15.5.2,
microsoft .NET framework version 4.7.02053
unity version 2019.2.0f1
ps: deleting cinemachine gives me the error (as expected):
Assets\Player\Scripts\System\BirdEyeSC.cs(2,7): error CS0246: The type or namespace name 'Cinemachine' could not be found (are you missing a using directive or an assembly reference?)
↧
The Issue with 'Func'
I'm having problems with addons defining their own version of 'Func' so that they can use the syntax from later versions of .NET.
The problem is that they don't define **func** in their own namespaces and instead define them in the application namespace, which means they inevitably conflict.
The package manager itself does this, so for example I can't use several .NET WebSocket classes with Unity without having to erase the package manager from the package cache *every single time I start Unity*, which gets very old.
Is it possible for Unity projects to override Func in their **own namespace** and not do so in the package namespace, which should prevent this problem from occurring? Is there any trivial workaround anyone has discovered to resolve this?
↧
In the 'Namespace' section of unity docs, I was confused by the following line...
*"Furthermore, you can use multiple bracketed namespace sections around classes wherever they occur, even if those classes are in different source files."*
↧
↧
Namespace inside DLL file
Hi guys,
I want to ask, if its possible to create DLL file from .cs file, which uses some namespaces from other script like:
using SomeNamespace // not Unity
namespace MyNamespace {
public static class MyClass {
//Some Scripts here where I use SomeNamespace
}
}
And then, create DLL file from my .cs file. Because Im trying to do something like this, but always I get error: **The type or namespace name could not be found. Are you missing an assembly reference?**
For creating DLL Im using Unity docs way:
-r:/Applications/Unity/Unity.app/Contents/Managed/UnityEngine.dll -target:library path-to-cs-file
Thank you very much
↧
IAPDemo Script Errors
I am implementing IAPs into my game however when i import the Unity IAP I get an "IAPDemo" script in the plugin folder which is giving me 9 errors.
![alt text][1]
[1]: /storage/temp/144515-errors.png
Iv never done IAPs before so I'm not sure if i am missing something.
I have IAPs turned on in the services window.
I just dont know where to go from here and the unity tutorials seem pretty useless.
↧
C# cant find a class auto generated by unity
Okay so I'm learning to use the new InputActions and I've created a C# scripts using
https://prnt.sc/oyaj5l
And this is what I got:
// GENERATED AUTOMATICALLY FROM 'Assets/PlayerControls.inputactions'
using System.Collections;
using System.Collections.Generic;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Utilities;
public class PlayerControls : IInputActionCollection
{
private InputActionAsset asset;
public PlayerControls()
{
///
}
}
But when I try to create an PlayerControls object, I get an error saying
> The type or namespace name 'PlayerControls' could not be found (are you missing a using directive or an assembly reference?)
This is the class where I try to reference it:
using System;
using UnityEngine;
using System.Collections;
using UnityStandardAssets.CrossPlatformInput;
using UnityStandardAssets.Utility;
using Random = UnityEngine.Random;
using UnityEngine.InputSystem;
namespace UnityStandardAssets.Characters.FirstPerson
{
public class FirstPersonController : MonoBehaviour
{
private PlayerControls controls; // ERROR HERE
}
}
↧
Can't access my namespaces inside Photon namespaces
Hello. II'm tryin' to create a custom type inside PUN2 networking. But whenever im tryin' to access my CardShuffle namespace it says :
Severity Code Description Project File Line Suppression State Suppression State
Error CS0246 The type or namespace name 'CardShuffle' could not be found (are you missing a using directive or an assembly reference?) PhotonUnityNetworking C:\Users\fello\CardShuffle_\Assets\Photon\PhotonUnityNetworking\Code\CustomTypes.cs
Even the CardShuffle namespace actually works inside other files than the Photon ones. Any help would be appreciated.
↧
↧
how to access script not derived from monobehavior ?
namespace Prototype.NetworkLobby
{
public class LobbyManager : NetworkLobbyManager
{
public void GoBackButton()
{
backDelegate();
topPanel.isInGame = false;
}
}
}
another script
public class Escape : MonoBehaviour
{
void Update()
{
if (Input.GetKeyDown("f"))
{
// call GoBackButton(); from here
}
}
}
↧
Unit Testing Version 2017.4.32
I am facing the script reference issue in this.
The type or namespace name `TestWebService' could not be found. Are you missing an assembly reference?
Over forum I am getting the solution for 2018 version. Kindly help me out of this.
↧
app with with multiple independent games
- i have a "mega" unity project containing: GameA and GameB
Each game has a submodule "sharedscriptsRepo"
containing scripts both games uses
- the games are loaded with Addressable and Asset Bundles system
- the issue: i cannot compile the "mega-project" because the files in "sharedscriptsRepo" are identical
(ERROR: namespace already contains a definition...)
- i want to keep the design that each Game has a reference to the shared-code because i dont want to be forced to update GameA to the latest version of "sharedscriptsRepo" once it becomes stable and passed QA tests and such
i couldn't find a solution for this and would love some help
↧
How does one resolve the CS0101 duplicate namespace when dealing with multiple assets who created this?
I see hundreds of CS0101 posts but nothing dealing with multiple PlayerController namespace issue. This would be a common and obvious name to use but the scripts belong to other asset builds that I bought in the store.
I do not want to change other devs code.
For instance Debug Graph and Oculus SocialStarter have the same namespace of PlayerController.
For me to alter this for a repair really throws a wrench in the monkeys.
Is there a switch that can be set to circumvent or repair this automagically when dealing with purchased assets?
Thank you in advance.
@Eric5h5 , @aldonaletto , @Bunny83 I added your names here because I have seen your answers in the past and they helped and corrected a lot of devs. I am asking for the same here as the topic entries might not get to you.
What I have shown here is not a coding error or any error on my part. I am asking for a top down, 30,000 mile, Global view on this.
↧
↧
,namespace cannot be found,Monodevelop issues, namespace cannot be found
I have no idea what's wrong. I keep experiencing this issues, I'm a newbbie please help thank you.
using UnityEngine.SceneManagement;
public class ShipScript : MonoBehaviour {
public float speed;
public GameObject laserPrefab;
public AudioClip explodeSound;
public AudioSource a_s;
public void Explosion() {
a_s.PlayOneShot(explodeSound);
}
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update ()
{
//If the left key is pressed, move the spaceship left
if (Input.GetKey ("left")) {
transform.Translate (new Vector3 (-speed, 0, 0) * Time.deltaTime, Space.World);
}
//If the right key is pressed, move the spaceship right
if (Input.GetKey ("right")) {
transform.Translate (new Vector3 (speed, 0, 0) * Time.deltaTime, Space.World);
}
//If the up key is pressed, move the spaceship up
if (Input.GetKey ("up")) {
transform.Translate (new Vector3 (0, speed, 0) * Time.deltaTime, Space.World);
}
//If the down key is pressed, move the spaceship down
if (Input.GetKey ("down")) {
transform.Translate (new Vector3 (0, -speed, 0) * Time.deltaTime, Space.World);
}
//If spacebar or left mouse button is pressed, have the spaceship fire a laser
if (Input.GetKeyDown ("space")) {
Instantiate (laserPrefab, transform.position, transfrom.rotation);
//GameObject laser1 = Instantiate (laserPrefab, transform.position, transform.rotation);
//GameObject laser2 = Instantiate (laserPrefab, transform.position, transform.rotation);
//GameObject laser3 = Instantiate (laserPrefab, transform.position, transform.rotation);
//public laser1 Instantiate (0, 0, 0);
//public laser2 Instantiate (0, 0, 15f);
//public laser3 Instantiate (0, 0, -15f);
}
if (Input.GetMouseButtonDown (0)) {
Instantiate (laserPrefab, transform.position, transform.rotation);
}
}
//Add the appropriate function here so that when the spaceship collides when another object, if that object is an alien or bomb(enemyshot),
//go to the game over scene
void OnTriggerEnter2D (Collider2D other) {
Animtor anim = this.GetComponent ();//get the ship animator component
if (other.CompareTag ("enemy") || other.CompareTag ("enemyshot")) {
playExplode ();
anim.Play ("ship_die");
}
}
void shipDead() {
SceneManager.LoadScene("game_over");
}
}
![alt text][1]
[1]: /storage/temp/151206-capture.jpg
↧
Async/Await in 2019.2 and Visual Studio 2019
I'm trying out Async instead of Couroutines.
In VS2019 w/ Unity 2019.2, the editor is recognizing 'async' and 'await', - but not recognizing 'Task'.
'Task' does not exist in the current context - am I missing a namespace or something?
Seems like its just supposed to work out of the box in the newer versions of Unity. Any help is appreciated, thank you,
Tim
↧
Referencing / Identifying Namespaces for Use in Scripts
Having a devil of a time finding the answer to this, all the answers seem to go to *"how to add a namespace to the top of your script,"* when I'm really looking for *"How do I identify **WHICH** namespace I **NEED** to add to the top of my script?"*
**Here's my Example (Unity 2019.3 - Universal Render Pipeline):**
I have a volume which changes some visual effects - See two helpful, general information tutorials:
1. https://youtu.be/LgMO7hRQRQs
2. https://www.youtube.com/watch?v=uzpUYBNsdb0
What I'd like to do is create only one volume for these effects (sort of moving-through-warps-in-space-time-effects) and then just use a script to adjust the **Weight** attribute of the Volume. I would set it at 1 when I need it to be visible, and 0 when I don't, and maybe I can Lerp between those values.
So I know that this weight attribute should be defined in a C# script, and that I could put something like ***using UnityEngine.Rendering.PostProcess.Volume*** up at the top of my script, then set up a variable like:
*private Volume theVolumeIWantToAdjust;*
Then I could do:
*theVolumeIWantToAdjust.Weight = 0.5;*
Shouldn't I be able to go to Unity Docs and see that UnityEngine has a class within it named Rendering, which has a class within it named PostProcess, which has something within it named Volume, which does all this list of things, so you reference each of those things like...whatever?
Am I just looking in the wrong places?
↧