I have been working anatomy type application. But i face this problem doesn’t know how to solve this issue. Whenever i try to rotate my camera around children object my script doesn’t work. Can someone help me with this. Thank you. Please view video below.
//this is the camera rotate script
using System;
using UnityEngine;
public class mongol : MonoBehaviour
{
public GameObject Obj = null;
public float minX = -360.0f;
public float maxX = 360.0f;
public float minY = -45.0f;
public float maxY = 45.0f;
public float sensX = 100.0f;
public float sensY = 100.0f;
float rotationY = 0.0f;
float rotationX = 0.0f;
float MouseX;
float MouseY;
void Update()
{
var x = Input.GetAxis("Mouse X");
var y = Input.GetAxis("Mouse Y");
if (x != MouseX || y != MouseY)
{
rotationX += x * sensX * Time.deltaTime;
rotationY += y * sensY * Time.deltaTime;
rotationY = Mathf.Clamp(rotationY, minY, maxY);
MouseX = x;
MouseY = y;
Obj.transform.localEulerAngles = new Vector3(-rotationY, rotationX, 0);
}
}
}