- Home /
Detecting click on specific object
Hi everyone;
I have nine cube rotating in my game. How I can stop one by clicking on it? I want it to be stopped after certain amount of time not immediately.
Thanks
Comment
generally you need ta' learn about raycasting, it's fun
Documentation/ScriptReference/Physics.Raycast.html
Answer by Kristian · Oct 09, 2012 at 11:40 AM
Here's an example in C#:
void Update()
{
//Clicking left mousebutton
if (Input.GetMouseButtonDown(0))
{
//Creating container for the raycast result
RaycastHit hitInfo = new RaycastHit();
//Making the raycast
if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hitInfo))
{
//Assuming animation is how you are rotating the cube
hitInfo.collider.animation.Stop();
}
}
}
Your answer
Follow this Question
Related Questions
Click To Delete Specific Object 1 Answer
Selecting gameobjects in game, 3 Answers
Click to destroy object 2 Answers
How Do You Exit A Game 0 Answers
How to disable click to move on interface elements ? 0 Answers