I have this code:
The target is a object with the tag named enemy
if (target)
{
if(target.gameObject.tag == "enemy")
{
// Rotate object to the target
Vector3 relativePos = target.position - transform.position;
Quaternion rotation = Quaternion.LookRotation (relativePos);
ball.transform.rotation = rotation;
}
if(Time.time >= nextFireTime )
{
FireProjectile();
}
}
I dont know why but the code was ment to just rotate the object, see the result in the video: