Question by 
               JungOmul · Dec 02, 2017 at 10:47 AM · 
                animationscripting problemraycastdoor  
              
 
              Raycasting Animations
Hi. I'm trying to make a door opened with Keycode "E". My idea is when I shoot raycast to the door, the distance is calculated, and if it is at right distance and the bool is false, animation door open is played. Here is my script
  using System.Collections;
  using System.Collections.Generic;
  using UnityEngine;
  
  public class Doors : MonoBehaviour {
  
      public Animation doorOpen;
      public Animation doorClose;
      bool isOpened;
  
  
      void Start()
      {
          doorOpen = GetComponent<Animation> ();
          doorClose = GetComponent<Animation> ();
          isOpened = false;
      }
  
      void Update ()
      {
          RaycastHit TheHit;
  
          if (Physics.Raycast (transform.position, transform.TransformDirection (Vector3.forward), out  TheHit, 30.0f)) {
              if (TheHit.collider.CompareTag ("Door")) {
                 if (!isOpened) {
                      if (Input.GetKeyDown (KeyCode.E)) {
                          doorOpen.Play ("Door_Open");
                      }
                  }
 
                  if (isOpened) {
                      if (Input.GetKeyDown (KeyCode.E)) {
                          doorClose.Play ("Door_Close");
                      }
                 }
              }
          }
      }
  }
What's the problem?? It doesn't make any error but when I press E, nothing happens.
               Comment
              
 
               
              Your answer
 
 
             Follow this Question
Related Questions
RayCast and Animation not working 0 Answers
Raycast to play animation 1 Answer
Something interesting with code 0 Answers
C# Door Script Problem 0 Answers
[C#]How to save a list of items to use in another script and it's not a player prefs type of list? 0 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
               
 
			 
                