While OnMouseDrag() is called, if I move mouse fast then OnMouseEnter() and OnMouseExit() are repeatedly called, so I made a new script but the same problem happens. If I move mouse slowly, they aren't called. I don't know what's the problem. Anyone can help me?
I hope they are not called while dragging. While I drag, the object is attached to the mouse so I think OnMouseEnter() and OnMouseExit() shouldn't be called.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class NewBehaviourScript : MonoBehaviour
{
private void OnMouseEnter()
{
// If mouse enters the object, the color of the object becomes red and prints "Enter"
Debug.Log("Enter");
GetComponent<SpriteRenderer>().color = Color.red;
}
private void OnMouseExit()
{
// If mouse exits the object, the color of the object becomes white and prints "Exit"
Debug.Log("Exit");
GetComponent<SpriteRenderer>().color = Color.white;
}
private void OnMouseDrag()
{
// If I click the object and drag, it follows mouse
// Then OnMouseEnter() and OnMouseExit() is called repeatedly
// and the color becomes red and white and both "Enter" and "Exit" are printed
// Utilities.MousePos has the position of mouse, and it doesn't have any problem.
transform.position = Utilities.MousePos;
}
}