Question by 
               MasiaT_max · Aug 16, 2016 at 03:39 PM · 
                animationscripting problemdoorif-else  
              
 
              Something interesting with code
Hey guys, I have a code for door animation. But in game when I press "E" , the door does animation twice. So, if the door was closed, I press E key and it's playing closing animation, then it opening and then it closing again, after that it's open. The same thing with closing. using UnityEngine; using System.Collections; using UnityEngine.Networking;
 public class Door : NetworkBehaviour {
 
     
     public Animator anim;
     [SyncVar] bool DoorOpen;
 
     void Start () {
         anim = GetComponent<Animator>();
         DoorOpen = false;
     }
 
     
     
     void OnTriggerStay(Collider col)
     {
         if (col.gameObject.tag == "Player" && Input.GetKeyDown(KeyCode.E) == true) {
 
             
                     if (DoorOpen == false)
                      {
                       DoorOpen = true;
                       //DoorControl("Open");
                      }
                     else
                      {
                       DoorOpen = false;
                       //DoorControl("Close");
                      }
             }
         }
 
     void Update()
     {
         if (DoorOpen == true)
         {
             DoorControl("Open");
         }
         else
         {
             DoorControl("Close");
         }
         Debug.Log(DoorOpen);
     }
 
 
     void DoorControl(string direction)
     {
         anim.SetTrigger(direction);
     }
 
     
 }
 
               Comment
              
 
               
              Your answer
 
 
             Follow this Question
Related Questions
Raycasting Animations 0 Answers
How can i stop my shooting animation after playing? 0 Answers
ANIMATION STRANGELY DOES NOT PLAY 0 Answers
2020.1.15f1 How to set animations "LoopTime" to false from script 2 Answers
Walking animation javascript? 2 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
               
 
			 
                