OnMouseDown, where is my error?


I’m trying to build something like a puzzle. Images are already at the correct spot but not with the correct rotation. The player has to click on the image to turn them.
I guess I’m making an error because this is not working. I find some topics such as OnMouseDown on another object - Questions & Answers - Unity Discussions dealing about that but I haven’t managed to reproduce it.

Here is the code I have so far:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Rotate : MonoBehaviour

public GameObject Object_A_Tourner;

void OnMouseDown()

    transform.Rotate(new Vector3(0f, 0f, 90f));



This code is apply to my 25 images, at this time nothing is moving when I click on one of them.
Have you any though?


As @dvidunis said, you need a collider on these objects. OnMouseDown only gets called if an object with a collider attached (or a GUIElement) is clicked on.

The reason that this is the case, is because a RayCast is performed and if that RayCast intersects a Collider, it will fire off the OnMouseDown method.