i attached the script below to an object. the purpose of this script is to enlarge the object when the mouse enter and then if the user click the left mouse button,it’s has to count(but for time being i just used debug.log to test the script). however, when i entered the mouse, the object enlarge but when i clicked, nothing happened.where did I do wrong? hope somebody can help me.Thank you
void OnMouseEnter ()
{
transform.localScale = new Vector3(2.0f,2.0f,2.0f);
if (Input.GetMouseButton (0))
{
Debug.Log("it's click");
}// end if
}
Hello @malbari68,
OnMouseEnter() is only called when mouse is entered inside the object. so called only once.
So you want to put this
void OnMouseEnter () {
transform.localScale = new Vector3(2.0f,2.0f,2.0f);
}
void Update () {
if(Input.GetMouseButtonDown (0))
{
Debug.Log("it's click");
}// end if
}
and might be you need this.
void OnMouseExit()
{
transform.localScale = new Vector3(0.5f,0.5f,0.5f);
}
Edited:
Or you use
void OnMouseDown() {
Debug.Log("it's click");
}
instead of
void Update () {
if(Input.GetMouseButtonDown (0))
{
Debug.Log("it's click");
}// end if
}