12345678910111213141516171819202122232425262728293031 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class FlyLogic : MonoBehaviour
- {
- public float YSpeed;
- // Start is called before the first frame update
- void Start()
- {
-
- }
- // Update is called once per frame
- void Update()
- {
- float height = this.transform.position.y;
- if (YSpeed > 0 && height < 10) this.transform.Translate(0, Time.deltaTime * YSpeed, 0);
- if (YSpeed < 0 && height > 1) this.transform.Translate(0, Time.deltaTime * YSpeed, 0);
- }
- public void Fly()
- {
- YSpeed = 1;
- }
- public void Land()
- {
- YSpeed = -1;
- }
- }
|