x


Error in script to make a monster shoot against the player

I have done a function to use in a script for one of my monsters (on my 3d plattaform game) and I have a problem with it, when I test the game, it crashes with unity and I have to terminate the process through Ctrl+alt+del. Do you have any idea what is going wrong?

Here you have the code (I have a rigidbody on unity too to use it as bullet, and its passed through the editor to the script):

var projectile : Rigidbody;

function Shoot () { while(true){ // Instantiate the projectile at the position and rotation of this transform var clone : Rigidbody; clone = Instantiate(projectile, transform.position, transform.rotation);

     // Give the cloned object an initial velocity along the current
     // object's Z axis
     clone.velocity = transform.TransformDirection (Vector3.forward * 10);
     }

// yield for one frame yield;
}

more ▼

asked May 06, 2011 at 06:14 PM

Infinity gravatar image

Infinity
141 105 78 83

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

You put yield outside of your infinite loop. Put in before the curly brace instead of after. If you line up your curly braces better, you'll have a better chance of catching mistakes yourself.

more ▼

answered May 06, 2011 at 06:19 PM

Jessy gravatar image

Jessy
18.4k 209 181 302

Thanks, now Unity don't crash, but there is a very weird effect on my script: Here you have a link on youtube about the effect, I have just recorded it : http://www.youtube.com/watch?v=b9xm_UZRqX0

May 06, 2011 at 08:26 PM Infinity

Please elaborate.

May 07, 2011 at 02:27 AM Jessy

elaborate what?

May 07, 2011 at 11:06 AM Infinity

I don't have a clue what is going right or wrong in that movie. Why didn't you narrate it?

May 07, 2011 at 02:54 PM Jessy
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

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

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x9517
x3762
x439
x31

asked: May 06, 2011 at 06:14 PM

Seen: 1006 times

Last Updated: May 06, 2011 at 06:14 PM