I’ve searched the forums and found many people having this problem and I’ve tried their solutions and I’ve even change the rotation of the model so it aligns properly to unity xyz but no matter what I do the turret changes to the opposite direction from the actual cube and the cube is the enemy. If I move the cube the turret targets the wrong way and moves as it should but just on the wrong way. I am new to scripting on unity… well I am new to much of unity so I have reached a point where my research over google has come empty. Any help would be appreciated. (I’ve also tried adding the turret to an empty object and made that turn 90deg. The turret still turns the wrong way) The project is on a 2d mode.
using UnityEngine;
using System.Collections;
[System.Serializable]
public class TurretFire : MonoBehaviour {
//TURRET LOCAL
public GameObject shot;
public Transform shotSpawn1;
public Transform shotSpawn2;
public float fireRate;
private float nextFire;
//LOOK AT TARGET
private GameObject target;
void Start(){
target = GameObject.FindWithTag ("Enemy");
}
void Update () {
//Automated Fire - TURRET
if(Time.time > nextFire){
nextFire = Time.time + fireRate;
Instantiate (shot, shotSpawn1.position, shotSpawn1.rotation);
Instantiate (shot, shotSpawn2.position, shotSpawn2.rotation);
}
//LOOK AT TARGET
transform.LookAt (transform.position + new Vector3 (0, 1, 0), target.transform.position - transform.position);
}
}