Guest User

Untitled

a guest
Nov 27th, 2020
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. using UnityEngine.SceneManagement;
  6.  
  7. public class Trigers : MonoBehaviour
  8. {
  9. enum triggers{Kill, RemoveObject, Teleport, Scene};
  10. [SerializeField] private triggers triggerType;
  11. [SerializeField] private string tag = "Player";
  12. [Space]
  13. [Header("Teleport")]
  14. public Text textToShow;
  15. public string textToShowText;
  16. public GameObject activateButton;
  17. public KeyCode activateKey;
  18. public Vector2 teleportTo;
  19. [Space]
  20. [Header("Scene")]
  21. public int sceneIndex;
  22.  
  23. bool teleportActive = false;
  24.  
  25. void OnTriggerStay2D(Collider2D collider)
  26. {
  27. if (collider.tag == tag)
  28. {
  29. switch(triggerType)
  30. {
  31. case triggers.Kill:
  32. SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
  33. break;
  34.  
  35. case triggers.RemoveObject:
  36. Destroy(collider.gameObject);
  37. break;
  38.  
  39. case triggers.Teleport:
  40. textToShow.text = textToShowText;
  41. activateButton.SetActive(true);
  42. print(teleportTo);
  43. if(teleportActive || Input.GetKeyDown(activateKey))
  44. {
  45. print(teleportTo);
  46. collider.gameObject.transform.position = new Vector3(teleportTo.x, teleportTo.y, collider.gameObject.transform.position.z);
  47. teleportActive = false;
  48. }
  49. break;
  50.  
  51. case triggers.Scene:
  52. SceneManager.LoadScene(sceneIndex);
  53. break;
  54. }
  55. }
  56. }
  57. void OnTriggerExit2D(Collider2D collider)
  58. {
  59. textToShow.text = "";
  60. activateButton.SetActive(false);
  61. }
  62. public void ButtonClick()
  63. {
  64. teleportActive = true;
  65. }
  66. }
  67.  
Advertisement
Add Comment
Please, Sign In to add comment