Advertisement
Guest User

Untitled

a guest
Sep 21st, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.04 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. using Valve.VR.InteractionSystem;
  6.  
  7. public class KeyLockTrigger : MonoBehaviour {
  8.  
  9. //public KeyLockInfo lockInfo;
  10. //private bool unlocked = false;
  11. //
  12. //void OnTriggerEnter(Collider info)
  13. //{
  14. // Key curKey = info.GetComponent<Key>();
  15. //
  16. // if (curKey == null)
  17. // {
  18. // return;
  19. // }
  20. //
  21. // print(curKey.transform.name);
  22. //
  23. // if (curKey == lockInfo.key)
  24. // {
  25. // curKey.LockInPosition(lockInfo);
  26. // }
  27. //}
  28.  
  29. public KeyLockInfo lockInfo;
  30.  
  31. public bool keyInArea;
  32.  
  33. private Key curKey;
  34.  
  35. private bool unlocked = false;
  36.  
  37. void OnTriggerEnter (Collider info)
  38. {
  39. curKey = info.GetComponent<Key>();
  40.  
  41. if (curKey == null)
  42. {
  43. return;
  44. }
  45.  
  46. if (curKey == lockInfo.key)
  47. {
  48. //if (key.transform.parent.GetComponent<Hand>().currentAttachedObject != key.gameObject)
  49. //{
  50. // print("working");
  51. // key.LockInPosition(lockInfo);
  52. //}
  53.  
  54.  
  55. //Hand curHand = curKey.transform.parent.GetComponent<Hand>();
  56. //
  57. //if (curHand != null)
  58. //{
  59. // keyInArea = true;
  60. //}
  61.  
  62. keyInArea = true;
  63. }
  64. }
  65.  
  66. void OnTriggerStay(Collider info)
  67. {
  68. if (curKey != null && info.transform != curKey.transform)
  69. {
  70. return;
  71. }
  72.  
  73. if (keyInArea && curKey.transform.parent == null && curKey == lockInfo.key && !unlocked && curKey.ableToOpenDoor)
  74. {
  75. unlocked = true;
  76.  
  77. curKey.LockInPosition(lockInfo);
  78. }
  79. }
  80.  
  81. void OnTriggerExit(Collider info)
  82. {
  83. if (info.transform == curKey.transform)
  84. {
  85. keyInArea = false;
  86. curKey = null;
  87. }
  88. }
  89.  
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement