I want to write a script which rotates the camera around the player when I hold the right mouse button down. I tried using this script I found somewhere on this site:
var target : Transform;
var distance = 5.0;
var xSpeed = 125.0;
var rightclicked : boolean = false;
private var x = 0.0;
@script AddComponentMenu("Camera-Control/Mouse Orbit")
function Start () {
var angles = transform.eulerAngles;
x = angles.y;
target = transform.parent.gameObject.GetComponent(Transform);
}
function Update (){
if (Input.GetMouseButtonDown(1)){
rightclicked = true;
}
else{
rightclicked = false;
}
}
function LateUpdate () {
if (target && rightclicked == true) {
x += Input.GetAxis("Mouse X") * xSpeed * distance* 0.02;
var rotation = Quaternion.Euler(0, x, 0);
var position = rotation * Vector3(0.0, 0.0, -distance) + target.position;
transform.rotation = rotation;
transform.position = position;
}
}
But this script doesn’t work. I want the camera to rotate around a GameObject, its parent when I hold down the right mouse button.
i am also making a game which requires a script like that but how i get to rotate around an object when clicked not just stay in one spot and look left and right?
using UnityEngine;
using System.Collections;
public class CameraRotate : MonoBehaviour
{
public Transform target;
int degrees = 0;
// Update is called once per frame
This version of Sovan’s Script will set the rotate speed to 10, then if not mouse button down, it will return it to 0, this should fix your problem you were having.