- Home /
My script doesnt respond what i wrote HELP!!!
Tell Me whats wrong with my script? cuz i dont get it... because the hole script work but the variable targetted always equal true when a gameobject is in the trigger, it doesnt repect the distance to set true or false the var targeted...see by your own....i did not put the variables list...but i think u can get it ....because there are so many i dont want mix up your mind...well....does repect what i wrote so... HELP PLZZ.. oh and the transform and the object that it supose to seee are rigidbodies....
function Update(){
if(!ObTarget==null)
{Objectdistance=Vector3.Distance(ObTarget.transform.position,Owner.position);}
if(!BObTarget==null)
{BObjectdistance=Vector3.Distance(ObTarget.transform.position,Owner.position);}
if(!Crate==null)
{CrateDistance=Vector3.Distance(ObTarget.transform.position,Owner.position);}
if(Crate==null&&ObTarget==null&&BObTarget==null){Targeted=false;} }
/
function OnTriggerStay(Hitting:Collider){
///////////OBJECTS
if(Hitting.gameObject.name=="Mine(Clone)"||Hitting.gameObject.name=="Mine")
{Crate=Hitting.gameObject; if(CrateDistance<4){Targeted=true;} if(CrateDistance>4{Targeted=false;}}
/
if(Hitting.gameObject.name=="Rocket(Clone)"||Hitting.gameObject.name=="Detonator Bomb(Clone)"||Hitting.gameObject.name=="Detonator Grenade(Clone)")
{ObTarget=Hitting.gameObject; if(Objectdistance<8){Targeted=true;}if(Objectdistance>8){ObTarget=null;Targeted=false;}}
/
if(Hitting.gameObject.tag=="Explosion")
{BObTarget=Hitting.gameObject; if(BObjectdistance<8{Targeted=true;}if(BObjectdistance>8){BObTarget=null;Targeted=false;}} }
/
/
function OnTriggerExit(Hitting:Collider) {
////////////OBJECTS
if(Hitting.gameObject.name=="Mine(Clone)"||Hitting.gameObject.name=="Mine"){Crate=null;Targeted=false;}
if(Hitting.gameObject.name=="Rocket(Clone)"||Hitting.gameObject.name=="Detonator Bomb(Clone)"||Hitting.gameObject.name=="Detonator Grenade(Clone)")
{ObTarget=null;Targeted=false;}
if(Hitting.gameObject.tag=="Explosion"){BObTarget=null;Targeted=false;}
you need to format your code, especially if it is this much. edit your post, select all the code and hit the "010101" button, otherwise no one is likely to bother trying to wade through this
and what is "Owner"? that is what you are using for your distance check, but what/where is it?
my guess is that the distance check is working fine, but it is always close enough.. try adding some debug logs:
function Update(){
if(ObTarget){
Objectdistance=Vector3.Distance(ObTarget.transform.position,Owner.position);
Debug.Log("Object Distance is: " + Objectdistance);
}
if(BObTarget){
BObjectdistance=Vector3.Distance(ObTarget.transform.position,Owner.position);
Debug.Log("B Object Distance is: " + BObjectdistance);
}
etc...
Owner is the object that the gameobject will be attach to...
and i already use a debug well....a print...and i already checked if the distance is fine and yes it is even if the object is far from the selected distance the variable still get true....so WTF?