DropEffectNode.cs 948 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.AI;
  5. public class DropEffectNode : MonoBehaviour
  6. {
  7. public Transform dropObj;
  8. bool _isStop = false;
  9. float desTime = 2;
  10. // Start is called before the first frame update
  11. void Start()
  12. {
  13. }
  14. // Update is called once per frame
  15. void FixedUpdate()
  16. {
  17. desTime -= Time.deltaTime;
  18. if(desTime <= 0)
  19. {
  20. Destroy(this.transform.parent.gameObject);
  21. }
  22. if (_isStop)
  23. {
  24. return;
  25. }
  26. if(dropObj)
  27. {
  28. dropObj.transform.position = this.transform.position;
  29. NavMeshHit hit;
  30. NavMesh.SamplePosition(dropObj.transform.position, out hit, 4, 1);
  31. }
  32. }
  33. public void SetDropItem(Transform item)
  34. {
  35. dropObj = item;
  36. }
  37. public void Stop()
  38. {
  39. _isStop = true;
  40. }
  41. }