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 sinokreal · Jan 20, 2012 at 02:05 PM · particlesparticleemitterparticleanimator

scripting a trigger to emit a flame on my character then..

Hello fellow game makers. I am rather new to Unity but have fundamental knowledge of the program and the basics on reading the script part in Unityscript. and some on c#

My question is i made this script so my wizard character can charge a fireball, then once the button is released he shoots the fireball. there is two problems i can't seem to figure out.

1: how to trigger the flames particles on his hands to emit once button is held down, and then they stop emitting once the button is let go.

2: he shoots the fireball after i let the button go, but i want him to charge the fireball in order to shoot it out while holding the button down, not shoot it every time the key is instantly pushed.

nyways heres the script, it was back engineered some what to the concept of the Tornado twins fireball script.

var fireballPrefab : Transform; var emit : boolean;

//spell casts variables here var cast1Animation : AnimationClip;

var cast1AnimationSpeed : float = 3.0;

function Update () {

    // Casting animation from casting to idle     
    if (Input.GetKey ("1"))
         animation.CrossFade ("cast1");
    else
         animation.CrossFade ("idle");
         
    // Fireball Relased after fire button is release.
  if (Input.GetButtonUp("Fire1")) { 
         
          var bullet = Instantiate(fireballPrefab,
          GameObject.Find("fireballSpawn").transform.position,
          Quaternion.identity);       
          bullet.rigidbody.AddForce(transform.forward * 1000);
  }

} function Start () {

          *******this part here dont work i get a message saying character********* 
          *******doesn't have ParticleMitter attched. which he does. its placed****
          *******on him as a child*************************************************


          // Emit Particles for 1 second
          particleEmitter.emit = true;
          yield WaitForSeconds(1);
          //Then Stop
          particleEmitter.emit = false;
          

}

any ideas or help will be great. thanks!

Comment
Add comment · Show 1
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 Mario Challenge · Aug 29, 2014 at 02:15 PM 0
Share

Back to the emitter thing were do you put the line of code?

5 Replies

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

Answer by Bicko · Jan 20, 2012 at 03:26 PM

Hey, welcome to UnityAnswers, I've found this place an immense resource and Get-Out-Of-Jail-Free card when you really get stuck.

What you need to know from the looks of it is that there are 3 different Input methods for buttons: Up, Down, and Stay (not actually called Stay, it's nameless). GetButtonUp runs code once when the button is released, GetButtonDown runs code once when the button is first pressed, GetButton runs code continuously while the button is held. You can have a read all about the various Input types on the Script Reference website here.

So for your case, what you'll want to do is:

  1. GetButtonDown: Spawn the fireball, and enable the particle emitter on his hands

  2. GetButton: Make it grow bigger for as long as this is running

  3. GetButtonUp: Launch the fireball, and disable the particle emitter on his hands

Now to get the particle emitter working, what you have to understand is that if you say particleEmitter.emit = true; then it only looks for an emitter on the object that this script is attached to. What you'll want to do is tell it to do this on a different object, like this:

 GameObject.Find("EMITTER NAME GOES HERE").particleEmitter.emit = true;

But obviously replacing "EMITTER NAME GOES HERE" with the name of the object that has the emitter on it.

Hope all this helps!

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
avatar image
0

Answer by sinokreal · Jan 22, 2012 at 03:23 AM

Thank you so much for that! You were right about the GameObject.Find part. as soon as I input the name of my particle prefab in there the particle started to emit. so now as the button is pressed the particle begins to materialize, as the button is let go the particle dissipates. I went back and redid the script (As shown Bellow) now to integrate the "GetButton" and another prefab with more emission to give the look as the fire is growing. I'll post the end result script once i get it working how I want. but for now the principle is there and I no longer need to crack my head open thanks to you sir.

Again thank you sir, your a life saver!!!!

function Update ()

{

  if (Input.GetButtonDown("Fire1"))

    {

    GameObject.Find("fireballTestEmit").particleEmitter.emit = true;

    }

  if(Input.GetButtonUp("Fire1"))

    {

     GameObject.Find("fireballTestEmit").particleEmitter.emit = false;

    }

}

function Start()

{

GameObject.Find("fireballTestEmit").particleEmitter.emit = 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
avatar image
0

Answer by sinokreal · Jan 22, 2012 at 03:22 AM

well that did work. now i have a new problem. I put the particle prefabs on each of his hands. when i hit the button to emit it, it turns on and off.

And now the animation doesn't play , plus only one hand emits the particles. The only other thing that does work is at the start when both particles don't emit as told by the Start function. Am I missing something here? heres the script. again any advice will be great! thanks again for the first part.

Script Bellow

function Update ()

{

    if (Input.GetButtonDown ("Fire1"))
         GameObject.Find("flameEmitL").particleEmitter.emit = true;     
         GameObject.Find("flameEmitR").particleEmitter.emit = true;
         animation.CrossFade("cast1");
   
    if (Input.GetButtonUp("Fire1"))
          
         GameObject.Find("flameEmitL").particleEmitter.emit = false;
         GameObject.Find("flameEmitR").particleEmitter.emit = false;
         animation.CrossFade("idle");

}

function Start ()

      {
      GameObject.Find("flameEmitL").particleEmitter.emit = false;
      GameObject.Find("flameEmitR").particleEmitter.emit = 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
avatar image
0

Answer by sam32x · Jan 22, 2012 at 04:03 AM

on the guys hand or staff or whatever

 function Update(){
 var hand : Transform;
 var fireParticles : GameObject;
 if(Input.GetButtonDown("Fire1")){
 Instantiate(fireParticles, hand.position, hand.rotation);
 }
 }

then on the fireParticles

 var chargeTime = 3
 var charged = 0;
 var fireball : GameObject;
 function Start() {
 Invoke("charged",chargeTime);
 }
 function Update(){
 if(Input.GetButtonUp("Fire1")){
 Destroy(gameObject)
 if(charged == 1){
 Instantiate(fireball, transform.position, transform.rotation);
 }
 }
 }
 
 function charged () {
 charged = 1;
 }

so when you click it will create the fire particles and if you release after chargeTime is up it will make a fireball

also you could put this on the fireball to make it shoot

 function Update(){
 Transform.Translate(Vector3.forward * Time.deltaTime * 30);
 }
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
avatar image
0

Answer by sinokreal · Jan 23, 2012 at 06:36 PM

Guys again. Thanks for you input, you helped me see the problem and resolve it as far as what i was going for.

This isn't the final script down bellow. But its the effect I am going for....well almost. Only thing to tweek is making an Interrupt while hes casting, also making the fireball release after the spell is cast instead of it releasing after i release the button. that will have to be another Question though. But for now here is the main body of the script and the idea I was after. Again thanks a lot guys.

var bulletPrefab : Transform; var explosionPrefab : Transform;

function Update () {

    if (Input.GetKey("1"))
     {
         GameObject.Find("flameEmitL").particleEmitter.emit = true;     
         GameObject.Find("flameEmitR").particleEmitter.emit = true;
         animation.Play("cast1");
         
         
     }
    if (Input.GetKeyUp("1"))
      {    
         GameObject.Find("flameEmitL").particleEmitter.emit = false;
         GameObject.Find("flameEmitR").particleEmitter.emit = false;
         animation.CrossFade("idle");
                 
         var bullet = Instantiate(bulletPrefab,
         GameObject.Find("fireballSpawn").transform.position,
         Quaternion.identity);       
         bullet.rigidbody.AddForce(transform.forward * 1000);

      }

}
function Start () { GameObject.Find("flameEmitL").particleEmitter.emit = false; GameObject.Find("flameEmitR").particleEmitter.emit = false; }

Comment
Add comment · Show 1 · 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 Bicko · Jan 23, 2012 at 08:09 PM 0
Share

If you want to interrupt the effect, then you could create a boolean variable along the lines of beenInterrupted, set it to false by default.

Then have it so that when the player is interrupted (takes damage, for example) you could Reset Input, although I'm not sure if this will work.. but the documentation says it "Resets all input" so I imagine it will. You may still have a problem with your Get$$anonymous$$eyUp working though.. in this case you'll want to change your if statement to:

 if (Input.Get$$anonymous$$eyUp("1") && !beenInterrupted)
 

So that it tests to see if the player has been interrupted. Note that I'm not using "beenInterrupted == false" -putting a '!' at the front of the variable does this for you! After this, you'll need to reset beenInterrupted back to false, so just add this immediately after your key up if statement:

 else
     beenInterrupted = false;

Another thing to note: if you're doing a statement that only does 1 thing, you don't need to encase it in parentheses. This will just keep your code smaller so you can browse through it faster.

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

7 People are following this question.

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

Related Questions

Shoot particles like motorcycle roost... 0 Answers

Laser Beam in Unity 0 Answers

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

How to change particles' view? 2 Answers

How do I use emissionRate in scripting? 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