Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using Valve.VR.InteractionSystem;
- public class KeyLockTrigger : MonoBehaviour {
- //public KeyLockInfo lockInfo;
- //private bool unlocked = false;
- //
- //void OnTriggerEnter(Collider info)
- //{
- // Key curKey = info.GetComponent<Key>();
- //
- // if (curKey == null)
- // {
- // return;
- // }
- //
- // print(curKey.transform.name);
- //
- // if (curKey == lockInfo.key)
- // {
- // curKey.LockInPosition(lockInfo);
- // }
- //}
- public KeyLockInfo lockInfo;
- public bool keyInArea;
- private Key curKey;
- private bool unlocked = false;
- void OnTriggerEnter (Collider info)
- {
- curKey = info.GetComponent<Key>();
- if (curKey == null)
- {
- return;
- }
- if (curKey == lockInfo.key)
- {
- //if (key.transform.parent.GetComponent<Hand>().currentAttachedObject != key.gameObject)
- //{
- // print("working");
- // key.LockInPosition(lockInfo);
- //}
- //Hand curHand = curKey.transform.parent.GetComponent<Hand>();
- //
- //if (curHand != null)
- //{
- // keyInArea = true;
- //}
- keyInArea = true;
- }
- }
- void OnTriggerStay(Collider info)
- {
- if (curKey != null && info.transform != curKey.transform)
- {
- return;
- }
- if (keyInArea && curKey.transform.parent == null && curKey == lockInfo.key && !unlocked && curKey.ableToOpenDoor)
- {
- unlocked = true;
- curKey.LockInPosition(lockInfo);
- }
- }
- void OnTriggerExit(Collider info)
- {
- if (info.transform == curKey.transform)
- {
- keyInArea = false;
- curKey = null;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement