- Home /
Visual Studios says that script doenst exist but it does.
So i started coding in c# and downloaded the standard assets for Unity 5 and Imported the Assets which included tech demos. Like that one scene where you can place flares and makes explosions. Now i took the explosion script and added a public static int which i now want to change in another script. But Visual Studios always says: "The name "ParticleSystemMultplier" does not exsit in the current context" So what im doing wrong?
Here is the script I started to make: using UnityEngine; using System.Collections;
public class Test : MonoBehaviour {
// Use this for initialization
void Changer () {
int particlesystemmultiplier = ParticleSystemMultiplier.test;
}
// Update is called once per frame
void Update () {
}
}
and here the modified ParticleSystemMultiplier script: using System; using UnityEngine;
namespace UnityStandardAssets.Effects
{
public class ParticleSystemMultiplier : MonoBehaviour
{
// a simple script to scale the size, speed and lifetime of a particle system
public static int test = 0;
public float multiplier = 1;
public class varchange : MonoBehaviour {int test = 1;}
void Start()
{ if (test == 1) {
var systems = GetComponentsInChildren<ParticleSystem>();
foreach (ParticleSystem system in systems)
{
system.startSize *= multiplier;
system.startSpeed *= multiplier;
system.startLifetime *= Mathf.Lerp(multiplier, 1, 0.5f);
system.Clear();
system.Play();
} }
}
}
}
Answer by wibble82 · Dec 22, 2015 at 10:34 AM
The class 'ParticleSystemMultiplier' has been placed inside the 'UnityStandardAssets.Effects' namespace:
//state we are inside the 'UnityStandardAssets.Effects' namespace
namespace UnityStandardAssets.Effects
{
//define a class called ParticleSystemMultiplier inside UnityStandardAssets.Effects
public class ParticleSystemMultiplier : MonoBehaviour
That means to access it from another script (that is NOT inside the UnityStandardAssets.Effects namespace) you either have to explicitly reference it using its full name (including namespace):
//access particle system multiplier using its 'fully qualified' name
int particlesystemmultiplier = UnityStandardAssets.Effects.ParticleSystemMultiplier.test;
Or make use of the 'using' statement at the top of your file, to tell the compiler it should look inside the UnityStandardAssets.Effects namespace whenever it comes across a name it can't find:
using UnityEngine;
using System.Collections;
using UnityStandardAssets.Effects;
public class Test : MonoBehaviour {
// Use this for initialization
void Changer () {
int particlesystemmultiplier = ParticleSystemMultiplier.test;
Hope that helps!
Note that usually if you hover the cursor over the bad name (will have squiggly red line under it), a question mark (or arrow or something) will usually appear to the left. Click this and VS will suggest potential classes you could be 'trying' to reference from other namespaces and offer to fix it. This won't always work, but often does the job.
-Chris
Also, I'm not sure on this but wouldn't a $$anonymous$$onoBehaviour declared inside a $$anonymous$$onoBehaviour fail? Never tried this one.
I think you've misunderstood my answer or I've misunderstood your comment! :).
I'm not suggesting that @Games$$anonymous$$aker redeclares any classes inside any other classes. Simply that the 'Test' script needs to be updated to either:
Have 'using UnityStandardAssets.Effects' at the top, so the compiler knows it should look there when it can't find ParticleSystem$$anonymous$$ultiplier
Fully qualify the ParticleSystem$$anonymous$$ultiplier with UnityStandardAssets.Effects.ParticleSystem.test
Not sure where you've picked up '$$anonymous$$onoBehaviour inside a $$anonymous$$onBehaviour' from - clearly I've explained myself badly somewhere, but I'm not sure where. Let me know if it's still confusing.
-Chris
Sorry, this wasnt directed at you :D Just kinda placing it here to tag it on to your answer.
I added the word 'Also' to make it read better.
Thank you for your help and especially that you explained the thing with the namespace it helped me very much. Also thanks for the tip with the question mark. Also sorry for the late respons because i wrote my questions actually quite some days ago but it took forever to get approved.