- Home /
fireball animation
im trying to make a adventure game were you have a person with magic abilitys who goes around doing quest. my problem is that ive made a script for the fireball shoot thing but when ever i play the game it says 'script error: update() can not be a coroutine' i dont know what that means so can someone help me please
heres my script:
var projectile : Rigidbody;
var speed = 20;
var Character : GameObject;
var FireballTime : int = 2;
function Update () {
if ( Input.GetButtonUp ("Fire1")) {
Character.animation.Play("fireball_cast");
yield WaitForSeconds( FireballTime);
clone = Instantiate(projectile, transform.position, transform.rotation);
clone.velocity = transform.TransformDirection( Vector3 (0, 0, speed));
Destroy (clone.gameObject, 3);
}}
thx in advanced
Answer by stingman · Jun 07, 2012 at 12:34 AM
Update makes a call every frame. You need to setup a coroutine to achieve what you want. Replace your code with this:
var projectile : Rigidbody;
var speed = 20;
var Character : GameObject;
var FireballTime : int = 2;
function Update () {
Fire();
}
function Fire() {
if ( Input.GetButtonUp ("Fire1")) {
Character.animation.Play("fireball_cast");
yield WaitForSeconds( FireballTime);
clone = Instantiate(projectile, transform.position, transform.rotation);
clone.velocity = transform.TransformDirection( Vector3 (0, 0, speed));
Destroy (clone.gameObject, 3);
}}
Answer by allenziff · Jun 07, 2012 at 04:35 PM
thx dude
No problem, but I have a few notes for you. I assume you might be somewhat new to Unity Answers. So first off, don't post comments as answers. Below my answer click "Add new comment." Also if the answer is correct then select the check mark next to the answer so others searching for the same thing can find it and it removes it from the "unanswered list" of questions.
Your answer
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
how to have a configurable joint model match a 3Dmesh animation 1 Answer
How to make a rigid obj walk. 0 Answers
Animation script with is.grounded help 0 Answers
How do I get one object to point toward another using rigidbody physics? 2 Answers