I’m not really sure how to put this but i get a NullReferenceException error in the AITrigger script, probably because the collider doesn’t have a transform attached to it but i need to access the transform on the same gameobject as the collider is attached to. The question is how? Here is the scripts (Only relevant parts):
AITrigger.cs
void OnTriggerEnter(Collider other) {
if (IsEnemy == "Yes") {
if(other.gameObject.tag == "Friendly" || other.gameObject.tag == "Player") {
PlayerPrefs.SetString(gameObject.name, "Yes");
AIPath AIPath = GetComponent<AIPath>();
sendthis = other.transform;
AIPath.SetTarget(sendthis);
}
}
if (IsEnemy == "No") {
if(other.gameObject.tag == "Enemy") {
PlayerPrefs.SetString(gameObject.name, "Yes");
AIPath AIPath = GetComponent<AIPath>();
sendthis = other.transform;
AIPath.SetTarget(sendthis);
}
}
}
AIPath.cs
public void SetTarget (Transform x) {
target = x;
}