ok i have a problem i want to send some information from one script that is a attached to game object A to game object B's script. i am trying to get these to objects to look at game object C. its all compiling and stuff but then gives me this error:
NullReferenceException: Object reference not set to an instance of an object
LookAt.Update () (at Assets/Scripts/LookAt.js:13)
i dont understand why, but here are my scripts attach to each objects.
GameObject A's Script: attackRTriggerStay.JS
@HideInInspector var targetAquired = false; var attackTarget; function OnTriggerEnter (other : Collider) { print(targetAquired); if(other.gameObject.CompareTag ("enemy")){ attackTarget = other.transform; targetAquired = true; print("targetAquired"); } } function OnTriggerExit (other : Collider) { if(other.gameObject.CompareTag ("enemy")){ targetAquired = false; print(targetAquired); } }Game Object B's Script: LookAt.JS
var getChildTrue : attackRTriggerStay; var getChildTarget : attackRTriggerStay; function start(){ getChildTrue = GetComponentInChildren(attackRTriggerStay); getChildTarget = GetComponentInChildren(attackRTriggerStay); } function Update () { if(getChildTrue.targetAquired == true){ transform.LookAt(getChildTarget.attackTarget); //.attackTarget is GameObject C } }