Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 midgear · Apr 11, 2013 at 10:29 PM · javascriptparticlesplatformerjetpackscrpt

Jetpack with other particles

Hi all, I'm doing some modifications to the "3D Platformer Tutorial". I added a mounted sword to the player, said sword has a particle effect attached, but because the "jetpack partial controller script" the sword particle only turns on when the played is jumping.

Is there a way to make it so the sword is going all the time and the flames to the jet pack only work when jumping?

Here is the code for the jump pack control for reference:

 private var litAmount = 0.00;
 
 function Start () {
 
     var playerController : ThirdPersonController = GetComponent(ThirdPersonController);
     
     // The script ensures an AudioSource component is always attached.
     
     // First, we make sure the AudioSource component is initialized correctly:
     audio.loop = false;
     audio.Stop();
     
     
     // Init the particles to not emit and switch off the spotlights:
     var particles : Component[] = GetComponentsInChildren(ParticleEmitter);
     var childLight : Light = GetComponentInChildren(Light);
     
     for (var p : ParticleEmitter in particles)
     {
         p.emit = false;
     }
     childLight.enabled = false;
 
     // Once every frame  update particle emission and lights
     while (true)
     {
         var isFlying = playerController.IsJumping();
                 
         // handle thruster sound effect
         if (isFlying)
         {
             if (!audio.isPlaying)
             {
                 audio.Play();
             }
         }
         else
         {
             audio.Stop();
         }
         
         
         for (var p : ParticleEmitter in particles)
         {
             p.emit = isFlying;
         }
         
         if(isFlying)
             litAmount = Mathf.Clamp01(litAmount + Time.deltaTime * 2);
         else
             litAmount = Mathf.Clamp01(litAmount - Time.deltaTime * 2);
         childLight.enabled = isFlying;
         childLight.intensity = litAmount;
                     
         yield;
     }
 }
 
 @script RequireComponent(AudioSource)
 


Keep in mind I am totally new to scripting so the more hand holding you can do the better.

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

Answer by RyanZimmerman87 · Apr 11, 2013 at 10:55 PM

Probably easiest to use separate gameObjects for each particle system, at least for the sake of this example.

So create an empty gameObject as a child of your character. Position it where you want the particle effect to be.

Create a public static jumpBool for all your objects to easily read.

Attach a particle system to your new Child gameObject.

  public static bool jumpBool = false;
 
 //if you want them both on the same object you could use this, and add in front of code;
 
     public ParticleSystem jumpParticles;
 
 Start()
 {
 //can probably just use 2nd of these two statements for this gameObject
 renderer.enabled = false;
 renderer.particleSystem.enableEmission = false;
 
 }
 
 
 //in your script on the new gameObject:
 
     void Update()
     {
     if (jumpBool == true)
     {
 
     renderer.particleSystem.enableEmission = true;
 //jumpParticles.renderer.particleSystem.enableEmission = true;
 
     }
 
 else renderer.particleSystem.enableEmission = false;
 // else jumpParticles.renderer.particleSystem.enableEmission = false;
     }
 
Comment
Add comment · 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

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

11 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Making 2d gun system but getting problem. 1 Answer

Particle System won't play on awake 0 Answers

Detecting Collision points of particles? 1 Answer

Im new at Unity 1 Answer

2D Platformer - Sidekick Follow Player 0 Answers


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