teleport.cs 828 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. public class teleport : MonoBehaviour
  6. {
  7. public GameObject player;
  8. public GameObject tp;
  9. private teleport nextTP;
  10. public bool isTeleport=false;
  11. public bool isTrap = false;
  12. void Start()
  13. {
  14. nextTP = tp.GetComponent<teleport>();
  15. }
  16. void OnTriggerEnter2D(Collider2D collision)
  17. {
  18. if (collision.gameObject.tag =="Player" && isTeleport)
  19. {
  20. isTeleport = false;
  21. StartCoroutine(Delay());
  22. }
  23. else if(isTrap)
  24. {
  25. }
  26. }
  27. private IEnumerator Delay()
  28. {
  29. player.transform.position = tp.transform.position;
  30. yield return new WaitForSeconds(10);
  31. nextTP.isTeleport = true;
  32. }
  33. }