Hey, i’m trying to make a hack and slash game, based on the tutorials, but, i’m with a problem, that’s my code:
using UnityEngine;
using System.Collections;
public class EnemyAI : MonoBehaviour {
public Transform target;
public int moveSpeed;
public int rotationSpeed;
private Transform myTransform;
public GameObject go;
// void awake(){
// myTransform = GetComponent<Transform>();
// }
// Use this for initialization
void Start () {
myTransform = GetComponent<Transform> ();
GameObject go = GameObject.FindGameObjectWithTag("Player");
target = go.transform;
}
void Update () {
Debug.DrawLine (target.position, myTransform.position);
// Look at target
myTransform.rotation = Quaternion.Slerp(myTransform.rotation , Quaternion.LookRotation(target.position - myTransform.position) , rotationSpeed * Time.deltaTime);
// Move towards target
myTransform.position += myTransform.forward * moveSpeed * Time.deltaTime ;
transform.position = myTransform.position;
transform.rotation = myTransform.rotation;
}
}
it says there’s a null reference exception on the line number 19 : “target = go.transform;” please help me
PS: Sorry my bad English