- Home /
how to make a camrea to rotate around a gameobject when drag mouse?
how to make a camrea to rotate around a gameobject when drag mouse?
i did this and it not working help. this is the script var target : Transform; var distance = 10.0;
var xSpeed = 250.0; var ySpeed = 120.0;
var y$$anonymous$$inLimit = -20; var y$$anonymous$$axLimit = 80;
private var x = 0.0; private var y = 0.0;
@script AddComponent$$anonymous$$enu("Camera-Control/$$anonymous$$ouse Orbit")
function Start () { var angles = transform.eulerAngles; x = angles.y; y = angles.x;
// $$anonymous$$ake the rigid body not change rotation
if (rigidbody)
rigidbody.freezeRotation = true;
}
function LateUpdate () { if (target) (target && Input.Get$$anonymous$$ouseButton(0)); { x += Input.GetAxis("$$anonymous$$ouse X")
Answer by duck · Oct 09, 2010 at 08:11 AM
There is a script supplied in the Scripts package in Unity's Standard Packages which almost has this behaviour - it orbits the object, but at all times, not just dragging. We can modify it to do this though!
To find it, either import the Scripts package when you create a new project, or to add it to an existing project, go to Assets -> Import Package, then browse to the Standard Packages folder inside the Unity application (program) folder.
It is in Scripts / Camera Scripts / Mouse Orbit
To use, place the script on your camera, then set the "Target" by dragging your target object into the target slot in the inspector.
A very simple modification to make the script work only when dragging, is this:
Double click on the script to edit it, and change line 26 from this:
if (target) {
to this":
if (target && Input.GetMouseButton(0)) {
Good luck!