using System.Collections; using System.Collections.Generic; using UnityEngine; public class DragonMovement : MonoBehaviour { [SerializeField] KeyCode FlapKey; Rigidbody2D _rigidbody; float _flapTime = 0f; [SerializeField] float FlapForce = 300f; [SerializeField] float FlapLength = .25f; bool _inCloud; private void OnTriggerEnter2D(Collider2D collision) { Debug.Log("ontriggerenter"); _inCloud = true; } private void OnTriggerExit2D(Collider2D collision) { _inCloud = false; } void Start() { _rigidbody = this.GetComponent(); } private void Update() { if (Input.GetKeyDown(FlapKey)) { _flapTime = FlapLength; } } void FixedUpdate() { if (_flapTime > 0f) { _rigidbody.AddForce(new Vector2(0f, FlapForce)); } _flapTime -= Time.deltaTime; float horizontalSpeed = .4f; if (_inCloud) { horizontalSpeed = -1f; } transform.position = new Vector3(transform.position.x + horizontalSpeed, transform.position.y, transform.position.z); } }