C# Door Script Problem
Hi. I made 2 animations with door open and close.
Use raycast to identify the distance with door -> The ray hits the door -> If bool door is not true -> if you press E -> Play door opening animation
It doesn't have any problem with raycasting and bool... But I think there is problem with my animation. I want my script using animations not "animator".
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");
                     }
                 }
             }
         }
     }
 }
 
               Please fix the script for me. Maybe I made a mistake on Raycasting too.. I'm not sure. Thanks
Your answer
 
             Follow this Question
Related Questions
Raycast to play animation 1 Answer
Raycast hit or miss in the same situation 1 Answer
Trying to make a door. Zoning or Load Level with Animation. 1 Answer
Moving enemy towards player while playing animation 0 Answers
When raycasting, script doesn't detect anything coming into ray yet I did everything right! 1 Answer