最近开始学习unity,遇到了一些看不懂的问题, 的值mouseClicked
是false
我一开始设置的,但是点击后我想设置为true
,然后问题就开始了,打印出来mouseClicked 的值同时是真假,怎么可能呢?
public class Button1 : MonoBehaviour
{
float movespeed = 0.5f;
float menuspeed = 5f;
bool mousEn = false;
bool mouseClicked = false;
GameObject iconNew;
GameObject dropQuad;
GameObject Mtx2;
void Start ()
{
iconNew = GameObject.FindGameObjectWithTag("IconNew");
dropQuad = GameObject.FindGameObjectWithTag("DropQuad1");
Mtx2 = GameObject.FindGameObjectWithTag("Mtxt2");
}
void Update ()
{
if (mousEn && transform.position.z>-0.3f)
{
transform.Translate(Vector3.back * movespeed * Time.deltaTime);
}
else if (!mousEn && transform.position.z<0f)
{
transform.Translate(Vector3.forward * movespeed * Time.deltaTime);
}
Debug.Log(mouseClicked); //both false and true
if (mouseClicked && Mtx2.transform.position.y>10f)
{
Mtx2.transform.Translate(Vector3.down * menuspeed * Time.deltaTime);
}
else if (!mouseClicked && Mtx2.transform.position.y!=12f)
{
Mtx2.transform.Translate(Vector3.up * menuspeed * Time.deltaTime);
}
}
void OnMouseEnter()
{
renderer.material.color = Color.gray;
mousEn = true;
}
void OnMouseExit()
{
renderer.material.color = Color.white;
mousEn = false;
}
void OnMouseDown ()
{
mouseClicked = !mouseClicked;
}
}