I am trying to get my game to "shoot" a projectile out from the location of an empty object. As of now it shoots every two seconds BUT it shoots a ton at once.
Here is my code for shooting.
function Shoot(seconds)
{
if(seconds!=savedTime)
{
var bullet : GameObject = Instantiate(bulletPrefab ,transform.Find("projRelease").transform.position ,Quaternion.identity);
bullet.rigidbody.AddForce(transform.forward * 1000);
savedTime=seconds;
}
}
And here is the part for seconds.
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);
}
}
}
I am also getting this error.
Invalid Cast Exception : Cannot cast from source type to destination type.
Thanks in advance :)