- Home /
Enemy Instantiating one bullet
I am busy developing for iphone and I had all my characters shooting properly. But for some reason the enemies started spraying bullet everywhere instead of just instantiating one bullet like it used to. Dunno when something changed but is there a way to make sure that it only makes one bullet every 2 seconds?
Here is my script that used to work..
var LookAtTarget:Transform;var damp = 4.0;
var BulletPrefab1 : Transform;
var savedTime = 0;
function Update () { if(LookAtTarget) { var rotate = Quaternion.LookRotation(LookAtTarget.position - transform.position);
transform.rotation = Quaternion.Slerp(transform.rotation, rotate, Time.deltaTime * damp);
var seconds : int = Time.time;
var oddeven = (seconds % 2);
if(oddeven)
{
Shoot(seconds);
}
}
}
function Shoot(seconds) { if(seconds!=savedTime) {
var bullet1 : GameObject = Instantiate(BulletPrefab1 ,transform.Find("spawnPoint2").position , Quaternion.identity);
savedTime=seconds;
}
}
Answer by renaldogoosen · Aug 17, 2011 at 11:44 AM
Hey again,
I found the issue.. I just had to move the "savedTime=seconds;" to before it asks to instantiate the bullet prefab.
Answer by DGArtistsInc · Aug 15, 2011 at 02:13 PM
try setting the savedTime to a private variable. Maybe that will work. Oh yeah the tornado twins on youtube is a great resource for this kind of thing try looking at some of their vids.
Answer by renaldogoosen · Aug 15, 2011 at 02:58 PM
Thank you very much.. Didn't seem to work but ill keep on tweeking as much as possible. worked fine on pc, then it touched mac (macintoss). Will watch some of their vids, maybe ill find the answer..
Your answer
Follow this Question
Related Questions
Setting bullet instansiate direction? help? 1 Answer
Shoot Bullet Delay Enemy 0 Answers
Add force to Instantiated object. 4 Answers
Hit enemy life 0 Answers
Problem with enemy shooting 4 Answers