因此,即时通讯正在Unity Engine中进行填字游戏,当我选择(使用左键单击)一个单词时,白色方块应变为绿色(出现),但是当我停止按住鼠标左键单击时,正如您在印刷品
上看到的那样,它不会再次变白代码在这里:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using System;
public class Selecionar : MonoBehaviour, ISelectHandler, IPointerClickHandler, IDeselectHandler {
private int acertos;
public static HashSet<Selecionar> todosMeusSelecionaveis = new HashSet<Selecionar>();
public static HashSet<Selecionar> selecionado = new HashSet<Selecionar>();
Renderer myRenderer;
[SerializeField]
Material materialNaoSelecionado;
[SerializeField]
Material materialSelecionado;
void Awake()
{
todosMeusSelecionaveis.Add(this);
myRenderer = GetComponent<Renderer>();
}
public void OnDeselect(BaseEventData eventData)
{
myRenderer.material = materialNaoSelecionado;
}
public void OnPointerClick(PointerEventData eventData)
{
if(Input.GetKeyDown(KeyCode.Mouse0)){
DeselectAll(eventData);
}
OnSelect(eventData);
}
public void OnSelect(BaseEventData eventData)
{
selecionado.Add(this);
myRenderer.material = materialSelecionado;
}
public static void DeselectAll (BaseEventData eventData){
foreach (Selecionar selecionavel in selecionado)
{
selecionavel.OnDeselect(eventData);
}
selecionado.Clear();
}
}
答案 0 :(得分:1)
我认为您应该在return
的{{1}}语句内if
。输入后,将执行OnPointerClick
,然后执行DeselectAll
。
可以:
OnSelect
或:
public void OnPointerClick(PointerEventData eventData)
{
if(Input.GetKeyDown(KeyCode.Mouse0)){
DeselectAll(eventData);
return; // <----
}
OnSelect(eventData);
}