Hello,
I do have the following code in the Update
void Update()
{
if (Input.GetMouseButton(0))
{
Vector2 _worldPoint = Camera.main.ScreenToWorldPoint(Input.mousePosition);
RaycastHit2D _hit = Physics2D.Raycast(_worldPoint, Vector2.zero);
if (_hit.collider != null)
{
MakeMove(int.Parse(_hit.collider.name));
Debug.Log(int.Parse(_hit.collider.name));
}
}
}
When I look in the console, whenever I hit (click) some gameobject on the screen, the Debug outputs 4-6 times of that gameObject’s name. That means the function MakeMove has been called 4-6 times, which is not the right behavior I’m looking for. I want it to be fired only once, when it has been clicked, until the next time when it will be clicked.
So, how to make it fire only once? but not 4-6 times? I do understand that is the behavior of Update, which runs every frame, but how can I make it work in my way?