/// Note: I took out all the code that were in
/// the functions that did not directly relate to creating or finding
/// the Gameobject with the tag
/// Code on the AI trying to find the player
/// It uses a predefined prefab of the player i drag into the variable
/// When i run the code it tells me "Could not find the player" so for some
/// reason go is = null when it is trying to set it as the playertransform
------------------------------------------------------------------------------
[RequireComponent (typeof(AdvancedMovement))]
[RequireComponent (typeof(SphereCollider))]
public class AI : MonoBehaviour {
public Transform target;
private Transform _myTransform;
void Awake (){
_myTransform = transform;
}
void Start () {
GameObject go = GameObject.FindGameObjectWithTag ("Player1");
if(go == null) {
Debug.LogError("Could not find the player!");
}
target = go.transform;
}
-----------------------------------------------------------------------------
/// This is the code that is Instantiating the player
public GameObject playerPrefab;
// Use this for initialization
void Awake () {
GameObject pc = Instantiate (playerPrefab, Vector3.zero, Quaternion.identity)as GameObject;
pc.name = "pc"; //name of character
_toon = new PlayerCharacter ();
_toon.Awake ();
_toon = pc.GetComponent<PlayerCharacter> ();
}