Search Unity

help with my particle emitter script....

Discussion in 'Scripting' started by etomp10291, May 23, 2011.

  1. etomp10291

    etomp10291

    Joined:
    Jan 11, 2010
    Posts:
    108
    Could someone help me with syntax of this script. I am trying to have particles emit as my vehicle moves forward. I have this much but it is not correct. I think I am on right track, just need a little help...THANKS!!


    Code (csharp):
    1.  
    2.  
    3. function Update () {
    4.  
    5. if (Vector3.forward > 1){
    6.  
    7.     particleEmitter.emit = true;
    8. }
    9.  
    10. else{
    11.  
    12.         particleEmitter.emit = false;
    13. }
    14. }
     
    Last edited: May 23, 2011
  2. Warrior1424

    Warrior1424

    Joined:
    Sep 30, 2010
    Posts:
    980
    Code (csharp):
    1. if (Vector3.forward >= 1){
    2.  
    Or
    Code (csharp):
    1. if (Vector3.forward => 1){
    2.  
    Can't remember.
     
  3. GargerathSunman

    GargerathSunman

    Joined:
    May 1, 2008
    Posts:
    1,572
    Set it up so that whenever the player hits the button for moving forward you turn on the emitter, and whenever the button stops being pressed you turn off the emitter.
     
  4. etomp10291

    etomp10291

    Joined:
    Jan 11, 2010
    Posts:
    108
    thought about that but need on AI cars also...thanks
     
  5. etomp10291

    etomp10291

    Joined:
    Jan 11, 2010
    Posts:
    108
    will try it, thanks!
     
  6. GargerathSunman

    GargerathSunman

    Joined:
    May 1, 2008
    Posts:
    1,572
    It's the exact same thing with the AI, only you replace the check for the input with a check for the AI deciding to move forward. Also, if you don't care which direction they're moving, you can use this:

    if (rigidbody.velocity.magnitude > .5) {

    }
     
  7. etomp10291

    etomp10291

    Joined:
    Jan 11, 2010
    Posts:
    108
    i like that...THANKS!!
     
  8. etomp10291

    etomp10291

    Joined:
    Jan 11, 2010
    Posts:
    108
    Should I apply script to vehicle or particle itself...just making sure, need to get this working :)
     
  9. GargerathSunman

    GargerathSunman

    Joined:
    May 1, 2008
    Posts:
    1,572
    Always put the rigidbody check on the object with the rigidbody.
     
  10. etomp10291

    etomp10291

    Joined:
    Jan 11, 2010
    Posts:
    108
    Thanks for the help, much appreciated!
     
  11. etomp10291

    etomp10291

    Joined:
    Jan 11, 2010
    Posts:
    108
    MissingComponentException: There is no 'ParticleEmitter' attached to the "AICar2" game object, but a script is trying to access it.
    You probably need to add a ParticleEmitter to the game object "AICar2". Or your script needs to check if the component is attached before using it.
    ParticleEmitVehicle.Update () (at Assets/ParticleEmitVehicle.js:5)


    Getting this error. how do I tell it where particle emitter is at?? It is attached to vehicle but does not recognize it....

    almost there:)
     
  12. etomp10291

    etomp10291

    Joined:
    Jan 11, 2010
    Posts:
    108
    wheels are turning now, haha! I found my mistake, thanks!!!
     
unityunity