I have a cycle going on here that is giving me problems i have an object (Monster1) that is passing over an cylinder (Attack Radius) that then sends information to the Cube(Tower). here is my code that does this:
attackRTriggerStay.JS (this is on the AttackRadius GameObject)
static var targetAquired = false;
var attackTarget;
function OnTriggerEnter (other : Collider) {
print(other);
print(targetAquired);
if(other.gameObject.CompareTag ("enemy")){
attackTarget = other;
targetAquired = true;
print(attackTarget);
print(targetAquired);
}
}
function OnTriggerExit (other : Collider) {
if(other.gameObject.CompareTag ("enemy")){
targetAquired = false;
print(attackTarget);
print(targetAquired);
}
}
The second script
LookAt.JS (This script is on the Tower GameObject)
var callTarget : attackRTriggerStay;
function Update () {
print(callTarget.attackTarget.gameObject);
if(callTarget.targetAquired == true){
print(callTarget.other);
transform.LookAt(callTarget.attackTarget);
}
}
my problem is this the var attackTarget isnt assigned to anything unitll it hits the collider then it is assigned the object that collided with it. that works all good in the first script, but then in the LookAt.JS script it gets completely confused because it thinks that the attackTarget doesnt have anthing attached to it yet… the error i am getting is NullReferenceException: Object reference not set to an instance of an object. when i know for a fact that it does have an instance… this is so frustrating does anybody know how i can get out of this viscous cycle that i am trapped in ?? it may be nooby, but i have been stuck on this thing for like 3 weeks now…