I need an object to disappear when my player is underneath it, what iv'e been attempting is using a 1 frame animation of the object going from it's position to -500Y, so essentially it disappears
problem is this all works on a collider, and have been experiencing lots of bugs doing this..
Is there an easier way to make an object not visible when the player is behind the object, im sure there is, im kinda very new to this so yeah...
please help >.<
this is the code im using so far
var doorOpened : boolean = false;
var roofDown : boolean = false;
var doorAudio : AudioClip;
var doorShut : AudioClip;
var timer : float = 0.0;
var ObjectVisiblity : Transform;
function Start(){
ObjectVisiblity.renderer.isVisible = true;
}
function OnControllerColliderHit(hit:ControllerColliderHit){
if((hit.gameObject.tag == "house1door")&&(doorOpened==false)){
openDoor();
roofDown = true;
}
}
function Update(){
if(doorOpened){
timer += Time.deltaTime;
}
if(timer >= 5){
shutDoor();
}
if (roofDown){
ObjectVisiblity.renderer.isVisible = false;
}
}
function shutDoor(){
var theHouse = gameObject.FindWithTag("house1");
theHouse.animation.Play("DoorClose");
theHouse.animation.Play("idle");
doorOpened = false;
timer = 0;
}
function openDoor(){
doorOpened = true;
var theHouse = gameObject.FindWithTag("house1");
theHouse.animation.Play("DoorOpen");
}
I keep getting thrown errors
Ok guys thanks for all the help :) this is what the finished script looks like, working and all, both answers helped me out in getting the final script :P thanks :D
var doorOpened : boolean = false;
var roofDown : boolean = false;
var doorAudio : AudioClip;
var doorShut : AudioClip;
var timer : float = 0.0;
var ObjectVisiblity : Transform;
var ShowMe = true;
function Start(){
ShowMe = true;
}
function OnControllerColliderHit(hit:ControllerColliderHit){
if((hit.gameObject.tag == "house1door")&&(doorOpened==false)){
openDoor();
ShowMe = false;
}
}
function Update(){
if(doorOpened){
timer += Time.deltaTime;
}
if(timer >= 5){
shutDoor();
}
if (ShowMe== false){
ObjectVisiblity.renderer.enabled = false;
}
}
function shutDoor(){
var theHouse = gameObject.FindWithTag("house1");
theHouse.animation.Play("DoorClose");
theHouse.animation.Play("idle");
doorOpened = false;
timer = 0;
}
function openDoor(){
doorOpened = true;
var theHouse = gameObject.FindWithTag("house1");
theHouse.animation.Play("DoorOpen");
}