2021년 4학년 1학기 기업연계프로젝트2 컴퓨터소프트웨어공학과 <원광투어팀> 팀장 : 송유진 팀원 : 김나영, 이경희, 한유진
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
1.1 KiB

5 years ago
  1. using UnityEngine;
  2. using System.Collections;
  3. public class SpawnObjectOnTriggerExit : MonoBehaviour
  4. {
  5. public GameObject effectTarget;
  6. public float delay = 1.0f;
  7. private Vector3 originPosition;
  8. private Quaternion originRotation;
  9. private GameObject clonedTarget;
  10. private void Start()
  11. {
  12. clonedTarget = effectTarget;
  13. originPosition = effectTarget.transform.localPosition;
  14. originRotation = effectTarget.transform.localRotation;
  15. }
  16. private void OnTriggerExit(Collider other)
  17. {
  18. if (other.gameObject == clonedTarget)
  19. {
  20. StopAllCoroutines();
  21. StartCoroutine(CopyTarget());
  22. }
  23. }
  24. private IEnumerator CopyTarget()
  25. {
  26. yield return new WaitForSeconds(delay);
  27. var copy = Instantiate(effectTarget);
  28. copy.transform.SetParent(effectTarget.transform.parent);
  29. copy.transform.localPosition = originPosition;
  30. copy.transform.localRotation = originRotation;
  31. copy.name = effectTarget.name;
  32. clonedTarget = copy;
  33. }
  34. }