So I have been having some trouble with shooting in unity not button shooting but AI shooting. I followed TornadoTwins tutorials on the turret but wanted some units to shoot faster or slower than others, but found that I couldn't change anything that would change rate of fire. so I tried a lot of stuff skipping boring story....
so over all I came to use this script:
var Turret : GameObject;
var Bullet : Transform;
var BulletSpeed = 5000;
var Character : Transform;
var SavedTime = 0;
if(Vector3.Distance(Character.position, transform.position)>20)
{
var Shoot : AnimationEvent = new AnimationEvent();
Shoot.time = 2.166;
Shoot.functionName = "SHOOT";
Turret.animation.clip.AddEvent(Shoot);
}
function SHOOT ()
{
var bullet = Instantiate(Bullet, transform.Find("X").transform.position, Quaternion.identity);
bullet.rigidbody.AddForce(transform.forward * BulletSpeed);
}
Now this works just fine but it shoots twice any suggestions on making it shoot once?
Thanks Guys~
K.N.