Unity3d 菜单按钮动画全部高亮显示
所以我是按照这个家伙的指导来做的 他最终也上传了所有教程的脚本、动画和预置。我想拥有完全相同的主菜单,在完成视频后,一些东西无法正常工作,我无法说出原因,例如,在播放时,整个菜单高亮显示,如果我按向上或向下箭头键(两次),它会选择/取消选择整个菜单按钮,如果在菜单处于“选定”状态时按空格键/回车键,则会触发整个菜单按钮上按下的动画。这是预制件的“检查器”选项卡之一的图像。所有其他按钮都具有完全相同的检查器选项卡,因为它们是原始按钮的副本 对于MenuButtonController的脚本Unity3d 菜单按钮动画全部高亮显示,unity3d,user-interface,animation,menu,Unity3d,User Interface,Animation,Menu,所以我是按照这个家伙的指导来做的 他最终也上传了所有教程的脚本、动画和预置。我想拥有完全相同的主菜单,在完成视频后,一些东西无法正常工作,我无法说出原因,例如,在播放时,整个菜单高亮显示,如果我按向上或向下箭头键(两次),它会选择/取消选择整个菜单按钮,如果在菜单处于“选定”状态时按空格键/回车键,则会触发整个菜单按钮上按下的动画。这是预制件的“检查器”选项卡之一的图像。所有其他按钮都具有完全相同的检查器选项卡,因为它们是原始按钮的副本 对于MenuButtonController的脚本 usi
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MenuButtonController : MonoBehaviour {
// Use this for initialization
public int index;
[SerializeField] bool keyDown;
[SerializeField] int maxIndex;
public AudioSource audioSource;
void Start () {
audioSource = GetComponent<AudioSource>();
}
// Update is called once per frame
void Update () {
if(Input.GetAxis ("Vertical") != 0){
if(!keyDown){
if (Input.GetAxis ("Vertical") < 0) {
if(index < maxIndex){
index++;
}else{
index = 0;
}
} else if(Input.GetAxis ("Vertical") > 0){
if(index > 0){
index --;
}else{
index = maxIndex;
}
}
keyDown = true;
}
}else{
keyDown = false;
}
}
}
您是否在所有菜单按钮上都指定了
thisIndex
值?很抱歉,我不知道您具体指的是哪个索引?如果您指的是脚本本身,则是一个名为MenuButton的按钮,则所有按钮都有相同的脚本插入我指的是名为thisIndex
的菜单按钮上的字段。如果它们都设置为同一个索引,那么它们都会高亮显示,因为它们都会检查自己的索引是否与控制器的索引匹配。哇,我非常愚蠢,你说得对,它们都在0索引上,我甚至没有注意到它作为一个可以更改的字段存在,在更改每个索引的值后,它们工作得完美无缺,非常感谢您的帮助,我已经做了3个小时了,我想我必须创建一个全新的菜单屏幕。非常感谢你,很抱歉浪费了你的时间
using System.Collections.Generic;
using UnityEngine;
public class MenuButton : MonoBehaviour
{
[SerializeField] MenuButtonController menuButtonController;
[SerializeField] Animator animator;
[SerializeField] AnimatorFunctions animatorFunctions;
[SerializeField] int thisIndex;
// Update is called once per frame
void Update()
{
if(menuButtonController.index == thisIndex)
{
animator.SetBool ("selected", true);
if(Input.GetAxis ("Submit") == 1){
animator.SetBool ("pressed", true);
Debug.Log("Pressing");
}
else if (animator.GetBool ("pressed")){
animator.SetBool ("pressed", false);
animatorFunctions.disableOnce = true;
}
}else{
animator.SetBool ("selected", false);
}
}
}