using System.Collections; using System.Collections.Generic; using UnityEngine; public class Helicopter : MonoBehaviour { //直升机类,控制第二关最后的直升机 public bool canGo = false;//记录自己目前是否可以前进了,在事件中改变 [Tooltip("填入直升机追踪的速度")] public float speed; void Start() { } // Update is called once per frame void Update() { if(canGo) { transform.position = new Vector3( // x加 transform.position.x + speed * Time.deltaTime, // yz不变 transform.position.y ,transform.position.z ); } } void OnTriggerEnter2D(Collider2D other) { if (other.tag == "Player") { Debug.Log("玩家被直升机发现,判定死亡"); //让直升机停下来 canGo = false; } } }