Guest User

key lock

a guest
Nov 16th, 2023
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | Gaming | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using System.Diagnostics;
  4. using UnityEngine;
  5. using UnityEngine.UI;
  6.  
  7. public class OpenGate : MonoBehaviour
  8. {
  9. public bool haskey;
  10. public float TheDistance;
  11. public GameObject ActionDisplay;
  12. public GameObject ActionText1;
  13. public GameObject Gate;
  14. public AudioSource GateSound;
  15.  
  16. void Update() {
  17. TheDistance = PlayerCasting.DistanceFromTarget;
  18. }
  19.  
  20. void OnMouseOver ()
  21. {
  22. if (TheDistance < 3) {
  23. ActionDisplay.SetActive (true);
  24. ActionText1.SetActive (true);
  25. }
  26. if (Input.GetButtonDown("Action"))
  27. {
  28. if (TheDistance <= 3)
  29. {
  30. if (haskey = true)
  31. {
  32. this.GetComponent<BoxCollider>().enabled = false;
  33. ActionDisplay.SetActive(false);
  34. ActionText1.SetActive(false);
  35. Gate.GetComponet<Animation>().Play("OpenGate");
  36. GateSound.Play();
  37. }
  38. }
  39. }
  40. }
  41. void OnMouseExit() {
  42. ActionDisplay.SetActive(false);
  43. ActionText1.SetActive(false);
  44. }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment