FlyLogic.cs 661 B

12345678910111213141516171819202122232425262728293031
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class FlyLogic : MonoBehaviour
  5. {
  6. public float YSpeed;
  7. // Start is called before the first frame update
  8. void Start()
  9. {
  10. }
  11. // Update is called once per frame
  12. void Update()
  13. {
  14. float height = this.transform.position.y;
  15. if (YSpeed > 0 && height < 10) this.transform.Translate(0, Time.deltaTime * YSpeed, 0);
  16. if (YSpeed < 0 && height > 1) this.transform.Translate(0, Time.deltaTime * YSpeed, 0);
  17. }
  18. public void Fly()
  19. {
  20. YSpeed = 1;
  21. }
  22. public void Land()
  23. {
  24. YSpeed = -1;
  25. }
  26. }