- Home /
Drawers to open and close
Hi i am newb at Unity scripting and i tried getting door open scripts working on a chest of drawers which has 3 drawers. I made an animation to open /close on timeline and I tried this script. I attached this script to MT gameobject, the game object itself and even the camera..Why does'nt it work. HELP!!
 private var doorIsOpen : boolean = false;
 var door : GameObject;
 function OnTriggerEnter(collision : Collider) 
 { 
     if ((collision.gameObject.tag =="DrawerAss1") && (doorIsOpen = false))
     {
         door.animation.Play("OpenDrawer"); 
         doorIsOpen = true;
     }
 }
 
 function OnTriggerExit(collision : Collider)
 {
     if ((collision.gameObject.tag == "DrawerAss1") && (doorIsOpen = true))
     {
         door.animation("CloseDrawer").speed = -1.0;
         doorIsOpen = false; 
     }  
 }
I even tried this from Unity script ref
 //Plays an animation only if we are not playing it already.
 function OnMouseEnter() {
     if (!animation.isPlaying)
         animation.Play();
nada...
First off, don't post a comment as a question ... Its not part of the 'code' ;). Now, lets take things nice and slowly. Question 1) - What is opening your drawers? Is it a player? Are you mouse clicking on them?
... You have not given enough information for anyone to help
Answer by oliver-jones · May 25, 2012 at 12:55 PM
In your script, in the if statements, change:
 if ((collision.gameObject.tag =="DrawerAss1") && (doorIsOpen = false)) {
 
to
 if ((collision.gameObject.tag =="DrawerAss1") && (doorIsOpen == false)) { 
You missed out the extra '='.
Hope this helps,
Ollie
Also, it helps the Unity community if you format your code correctly (when copy and pasting, highlight your code and press the (101010) icon :)
Your answer
 
 
             Follow this Question
Related Questions
Why is my door opening and closing at the same time????????? 2 Answers
Door Opening And Closing 2 Answers
Open/close door, lags if I walk into it. 0 Answers
Open AND CLOSE webpage 1 Answer
isOpen queues next door to run close animation even if its closed 0 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                