Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by GamesMaker · Dec 22, 2015 at 08:12 AM · c#scripting problemintvisualstudio

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();
             } }
         }
     }
 }
 
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

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

Comment
Add comment · Show 5 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image meat5000 ♦ · Dec 22, 2015 at 11:50 AM 0
Share

Also, I'm not sure on this but wouldn't a $$anonymous$$onoBehaviour declared inside a $$anonymous$$onoBehaviour fail? Never tried this one.

avatar image wibble82 meat5000 ♦ · Dec 22, 2015 at 11:54 AM 0
Share

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

avatar image meat5000 ♦ wibble82 · Dec 22, 2015 at 12:38 PM 0
Share

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.

Show more comments
avatar image GamesMaker · Dec 22, 2015 at 06:58 PM 0
Share

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.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Integer value randomly multiples itself by 3 or 2 for seemingly no reason. 2 Answers

Int Switch always chooses same value 1 Answer

Should I make an interface to avoid direct reference of concrete classes in this case? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges