Hey guys, simply enough evolving a script i’ve been using for sometime, i want the player to be chased by a fish when it enters a volume, and stopped being chased when it leaves the volume. However, it just doesnt stop.
fishScript:
var lookAtTarget : Transform;
var speed = 6;
var damp = 0;
var canMove : boolean;
function Awake(){
if (!lookAtTarget)
{
lookAtTarget = GameObject.FindWithTag("Player").transform;
}
}
function start(){
var indepth : waterScript;
indepth = gameObject.GetComponent("waterScript");
canMove = false;
}
function Update(){
if (waterScript.inwater == true){
canMove = true;
if (waterScript.inwater == false){
canMove = false;
}
if(canMove == true){
transform.LookAt(lookAtTarget);
var rotate = Quaternion.LookRotation(lookAtTarget.transform.position - transform.position);
transform.rotation = Quaternion.Slerp(transform.rotation, rotate, damp);
transform.Translate (0,0,speed*Time.deltaTime);
}
if(canMove == false){
transform.Translate (0,0,0);
}
}
}
and the waterscript:
static var inwater : boolean;
function Start(){
inwater = false;
}
function OnTriggerEnter(otherObject: Collider){
if(otherObject.gameObject.tag == "Player"){
inwater = true;
}
}
function onTriggerExit (otherObject : Collider){
if(otherObject.gameObject.tag == "Player"){
inwater = false;
}
}
Doesn’t really make any sense…