Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class OpenCloseDoor : MonoBehaviour
- {
- Animator anim;
- bool playerInTrigger = false;
- public bool doorIsClosed = true;
- public Transform playerTrans;
- private void Start()
- {
- anim = GetComponent<Animator>();
- playerTrans = GameObject.FindWithTag("Player").transform;
- }
- private void OnTriggerEnter(Collider other)
- {
- if (other.CompareTag("Player"))
- {
- playerInTrigger = true;
- }
- }
- private void OnTriggerExit(Collider other)
- {
- if (other.CompareTag("Player"))
- {
- playerInTrigger = false;
- }
- }
- private void Update()
- {
- if (playerInTrigger && Input.GetMouseButtonDown(0))
- {
- if (doorIsClosed)
- {
- anim.SetTrigger("open");
- doorIsClosed = false;
- }
- else
- {
- anim.SetTrigger("close");
- doorIsClosed = true;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement