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;
- public bool doorIsClosed = true;
- public int minDistance = 10;
- public Transform playerTrans;
- private void Start()
- {
- anim = GetComponent<Animator>();
- playerTrans = GameObject.FindWithTag("Player").transform;
- }
- private void Update()
- {
- if (Input.GetMouseButtonDown(0))
- {
- if (Vector3.Distance(this.gameObject.transform.position, playerTrans.position) <= minDistance)
- {
- if (doorIsClosed)
- {
- anim.SetTrigger("open");
- doorIsClosed = false;
- }
- else
- {
- anim.SetTrigger("close");
- doorIsClosed = true;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement