currentAnim.frame === 3) this.kill();

本文探讨了在动画编程中如何根据当前帧数进行对象控制的方法。特别地,当动画达到指定帧时,实现对象的销毁逻辑。这对于游戏开发和动画制作非常重要。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

    if (this.currentAnim.frame === 3) this.kill();
using UnityEngine; using UnityEngine.UI; using System.Collections.Generic; public class AvatarSelector : MonoBehaviour { [Header("UI References")] public GameObject avatarButtonPrefab; public Transform contentParent; public Image selectedAvatarDisplay; [Header("Avatar Settings")] public Sprite[] avatarSprites; private List<Button> avatarButtons = new List<Button>(); private int selectedIndex = -1; void Start() { CreateAvatarButtons(); // 默认选择第一个头像 if(avatarSprites.Length > 0) { SelectAvatar(0); } } void CreateAvatarButtons() { // 清除现有按钮 foreach(Transform child in contentParent) { Destroy(child.gameObject); } avatarButtons.Clear(); // 创建新按钮 for(int i = 0; i < avatarSprites.Length; i++) { int index = i; // 捕获当前索引 GameObject buttonObj = Instantiate(avatarButtonPrefab, contentParent); Button button = buttonObj.GetComponent<Button>(); Image image = buttonObj.GetComponent<Image>(); Outline outline = buttonObj.GetComponent<Outline>(); // 设置头像 if(image != null) { image.sprite = avatarSprites[index]; } // 添加点击事件 button.onClick.AddListener(() => SelectAvatar(index)); // 添加到列表 avatarButtons.Add(button); } } void SelectAvatar(int index) { // 取消之前的选择 if(selectedIndex >= 0 && selectedIndex < avatarButtons.Count) { Outline prevOutline = avatarButtons[selectedIndex].GetComponent<Outline>(); if(prevOutline != null) { prevOutline.enabled = false; } } // 设置新的选择 if(index >= 0 && index < avatarButtons.Count) { Outline outline = avatarButtons[index].GetComponent<Outline>(); if(outline != null) { outline.enabled = true; } // 更新显示的头像 if(selectedAvatarDisplay != null && avatarSprites.Length > index) { selectedAvatarDisplay.sprite = avatarSprites[index]; } selectedIndex = index; // 保存选择 PlayerPrefs.SetInt("SelectedAvatar", index); Debug.Log($"Selected avatar index: {index}"); } } }分析代码
06-08
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值