【发布时间】:2020-05-29 23:22:22
【问题描述】:
我正在开发一个汽车游戏项目。我制作了一个 UI 面板,其中有两个 UI 图像(Left_Image 和 Right_Image)。当我按下“左”按钮时,Left_Image 开始闪烁,当我按下“右”按钮时,Right_Image 开始闪烁。但我想要的是,如果 Right_Image 已经闪烁并且我按下“左”按钮,那么 Left_Image 开始闪烁但 Right_Images 应该停止。我已经尝试了所有技巧,但没有运气。请帮忙。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Indicators_UI : MonoBehaviour {
public GameObject flash_right;
public GameObject flash_left;
public float interval;
void Start()
{
InvokeRepeating("RightFlash", 0, interval);
InvokeRepeating("LeftFlash", 0, interval);
}
void Update ()
{
if (ControlFreak2.CF2Input.GetAxis ("right") != 0) {
if (!IsInvoking("RightFlash"))
InvokeRepeating("RightFlash", 0.35f, 0.35f);
}
else
{
CancelInvoke("RightFlash");
}
if (ControlFreak2.CF2Input.GetAxis ("left") != 0) {
if (!IsInvoking("LeftFlash"))
InvokeRepeating("LeftFlash", 0.35f, 0.35f);
}
else
{
CancelInvoke("LeftFlash");
}
}
void RightFlash()
{
if(flash_right.activeSelf)
flash_right.SetActive(false);
else
flash_right.SetActive(true);
}
void LeftFlash()
{
if(flash_left.activeSelf)
flash_left.SetActive(false);
else
flash_left.SetActive(true);
}
}
【问题讨论】:
-
为什么不只是添加一个布尔值并拥有 flashleft、flashright 并相应地设置和使用它们
标签: c# unity3d user-interface 3d repeat