在Unity中,你可以使用以下腳本來(lái)實(shí)現(xiàn)點(diǎn)擊按鈕時(shí)停止動(dòng)畫(huà)的功能:
using UnityEngine;
using UnityEngine.UI;
public class StopAnimationOnClick : MonoBehaviour
{
? ? public Animator animator;
? ? public Button button;
? ? private bool isAnimationPlaying = true;
? ? private void Start()
? ? {
? ? ? ? button.onClick.AddListener(OnButtonClick);
? ? }
? ? private void OnButtonClick()
? ? {
? ? ? ? if (isAnimationPlaying)
? ? ? ? {
? ? ? ? ? ? animator.enabled = false;
? ? ? ? ? ? isAnimationPlaying = false;
? ? ? ? }
? ? ? ? else
? ? ? ? {
? ? ? ? ? ? animator.enabled = true;
? ? ? ? ? ? isAnimationPlaying = true;
? ? ? ? }
? ? }
}
這個(gè)腳本假設(shè)你已經(jīng)有一個(gè)Animator組件和一個(gè)Button組件。你需要將Animator組件分配給animator變量,并將Button組件分配給button變量。然后,當(dāng)按鈕被點(diǎn)擊時(shí),腳本會(huì)切換動(dòng)畫(huà)的enabled屬性來(lái)停止或播放動(dòng)畫(huà)。文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-859583.html
將該腳本附加到包含Animator和Button組件的游戲?qū)ο笊?,然后你就可以通過(guò)點(diǎn)擊按鈕來(lái)停止或播放動(dòng)畫(huà)了。文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-859583.html
到了這里,關(guān)于Unity中,點(diǎn)擊按鈕Button,控制,動(dòng)畫(huà)Animator暫停播放的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!