过关功能实现
说明:过关时开启ui,切换状态为vitory,落地后再播放动画。
VictoryScreen中增加代码:订阅按钮功能,唤出鼠标指针。
using UnityEngine; using UnityEngine.UI; public class VictoryScreen : MonoBehaviour { [SerializeField] VoidEventChannel levelClearedEventChannel; [SerializeField] Button nextLevelButton; private void OnEnable() { levelClearedEventChannel.AddListener(ShowUI); nextLevelButton.onClick.AddListener(SceneLoader.LoadNextScene); } private void OnDisable() { levelClearedEventChannel.RemoveListener(ShowUI); nextLevelButton.onClick.RemoveListener(SceneLoader.LoadNextScene); } private void ShowUI() { GetComponent<Canvas>().enabled = true; GetComponent<Animator>().enabled = true; Cursor.lockState = CursorLockMode.None; } }
|
PlayerState_Land的LogicUpdate中添加判定,如果玩家胜利,则切换为PlayerState_Victory状态。
PlayerState_Victory状态主要进行随机播放获胜音效。
public class PlayerState_Victory : PlayerState { [SerializeField] AudioClip[] voice; public override void Enter() { base.Enter(); input.DisableGamePlayInputs(); player.voicePlayer.PlayOneShot(voice[Random.Range(0, voice.Length)]); } }
|