using System.Collections; using System.Collections.Generic; using UnityEngine; public class Helicopter : MonoBehaviour { //直升机类,控制第二关最后的直升机 public bool canGo = false;//记录自己目前是否可以前进了,在事件中改变 [Tooltip("填入直升机追踪的速度")] public float speed; [Tooltip("拖入枪击音效")] public AudioSource gunSound; [Tooltip("拖入第二关的普通BGM,死亡后得换回普通BGM")] public AudioClip normalClip; 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("玩家被直升机发现,判定死亡"); other.GetComponent().YouAreShootingDead(); gunSound.Play(); FindObjectOfType().ChangedTheBGM(normalClip); //让直升机停下来 canGo = false; } } }