I just want to rotate an object by clicking the object…but when I used two objects and have the same script, they both rotate… what I want is to rotate one object when I click, and then when I click the other object it also rotate…please help me guys~
Please use Code Tags when posting code on the forum.
Your script doesn’t do what you think it does. You’re simply checking that a click has happened, and not what/where the click is in relevance to anything. All objects with that script on will rotate whenever you click.
no sir… I’m creating an app for interior design that have edit tools… like can select and dropNdrag furnitures, can delete,can rotate and scale it. please help me with this… I’m only student this is for our project…
Using right click gets a little trickier, but this script is the simplest way I could find. Note that the behaviour is changed slightly and the objects will stop rotating as soon as the mouse moves off them (in the old script they only stopped when the button came up)
using UnityEngine;
using System.Collections;
public class Rotate : MonoBehaviour {
private bool mouseDown = false;
void Update ()
{
if (mouseDown)
transform.Rotate(0,0, Time.deltaTime*110);
mouseDown = false;
}
void OnMouseOver ()
{
if (Input.GetMouseButton(1))
{
mouseDown = true;
}
}
}