I have been trying to implement a feature in my game where a turret should detect an enemy, it then fires an arrow at the enemy which follows the target. I have been trying to use the LookAt function to accomplish this but it is safe to safe I have been unsuccessful. Here is the code.
public class TurretScriptTest : MonoBehaviour {
public GameObject arrowPrefab;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
void OnTriggerEnter(Collider other)
{
if (other.gameObject.tag == "Enemy")
{
//Destroy(other.gameObject);
GameObject arrowPrefab=(GameObject)Instantiate(
arrowPrefab,
transform.position,transform.rotation);
transform.position =other.gameObject.position;
transform.LookAt(other.gameObject);
}
}
}
If any one has any advice please help!