TestItem.cs 839 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class TestItem : MonoBehaviour {
  5. private Rigidbody mRig;
  6. void Start () {
  7. mRig = this.GetComponent<Rigidbody>();
  8. }
  9. // Update is called once per frame
  10. void Update () {
  11. }
  12. private void LateUpdate()
  13. {
  14. Move();
  15. }
  16. private float cd = 1;
  17. private float fullTime = 0.5f;
  18. private float duringTime;
  19. private void Move()
  20. {
  21. if(duringTime > fullTime)
  22. {
  23. duringTime = -cd;
  24. }
  25. if(duringTime < fullTime && duringTime >=0)
  26. {
  27. duringTime += Time.deltaTime;
  28. this.mRig.AddForce(Vector3.right * 2);
  29. }
  30. else
  31. {
  32. duringTime += Time.deltaTime;
  33. }
  34. }
  35. }