Advertisement
kadyr

Untitled

Jul 17th, 2021
1,133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.76 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class DoorOpenScript : MonoBehaviour
  6. {
  7.     // Start is called before the first frame update
  8.     bool isOpen = false;
  9.     private Animator anim;
  10.     void Start()
  11.     {
  12.         anim = GetComponent<Animator>();
  13.     }
  14.  
  15.     // Update is called once per frame
  16.     void Update()
  17.     {
  18.         if(Input.GetKeyDown(KeyCode.E) && Vector3.Distance(GameObject.FindObjectOfType<PlayerController>().transform.position, transform.position) < 10f)
  19.         {
  20.             if (isOpen)
  21.             {
  22.                 isOpen = false;
  23.             }
  24.             else
  25.             {
  26.                 isOpen = true;
  27.             }
  28.             anim.SetBool("isOpen", isOpen);
  29.         }
  30.     }
  31. }
  32.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement