Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Particle Playground 2 NOT Working With Javascript

Discussion in 'Scripting' started by keenanwoodall, Sep 21, 2014.

  1. keenanwoodall

    keenanwoodall

    Joined:
    May 30, 2014
    Posts:
    597
    I literally just want to change the emission rate, but it won't let me access the script for the life of me!
    Code (csharp):
    1.  
    2. var emission : int = 1000;
    3. private var particle : PlaygroundParticles;
    4.  
    5. function Start ()
    6. {
    7.     particle = GetComponent(PlaygroundParticles);
    8. }
    9.  
    10. function Update ()
    11. {
    12.     if(Input.GetMouseButton(0))
    13.         particle.emissionRate = emission;
    14.     else
    15.         particle.emissionRate = 0.0;
    16. }
     
  2. LateBindingLover

    LateBindingLover

    Joined:
    Sep 22, 2014
    Posts:
    2
    Pssst. your C# code looks a lot like Unityscript.

    That public emission variable is exposed to the inspector, so its actual value is determined from that value not the script. But I doubt that's it judging by your post count you would of already discovered that potential "feature.". Sorry thats all I got since I haven't started playing with particles yet. But maybe its how you are getting the reference, perhaps the source is c# so use a "string" instead of type.

    http://docs.unity3d.com/ScriptReference/Component.GetComponent.html
     
  3. keenanwoodall

    keenanwoodall

    Joined:
    May 30, 2014
    Posts:
    597
    Sorry, I don't really understand what your saying in the first part of your post. As to the second part, I tried getting the component inside of quotations but that didn't work.
     
  4. Dustin-Horne

    Dustin-Horne

    Joined:
    Apr 4, 2013
    Posts:
    4,568
    Try putting the ParticlePlayground stuff inside of a /Plugins folder to make sure it's accessible to Unityscript if it's a source code asset. It could be an issue of compilation order (the javascript can't access it because the C# stuff compiles after the javascript stuff unless it's in a plugins folder).
     
  5. keenanwoodall

    keenanwoodall

    Joined:
    May 30, 2014
    Posts:
    597
    Ok, thanks. I've had problems with compiling order before but the error didn't seem like it was a result of compiling problems. The error was that Unity didn't recognize the variable type.