Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

206
Vistas
Unity. How to create a rotating camera around an object with the change of this object

I want to make a rotating camera on the map around the target object, with the first point I did it. After clicking on another object, which I also want to inspect, my camera shifts and rotates not around the object, but some other point. How to point to an object around which I want the camera to rotate with the mouse

LabsManager lab;

public Transform lookCentre;
public Transform lookZRU;
public Vector3 offset;
public float sensitivity; // чувствительность мышки
public float limit; // ограничение вращения по Y
public float zoom; // чувствительность при увеличении, колесиком мышки
public float zoomMax; // макс. увеличение
public float zoomMin; // мин. увеличение
private float X, Y;
bool activeTarget;


void Start()
{
    GameObject activ = GameObject.Find("LabsManager");
    lab = activ.GetComponent<LabsManager>();
    activeTarget = false;
}


void Update()
{
    if (lab.LabName == "Осмотр")
    {
        if (activeTarget == false)
        {
            CameraPosition(lookCentre);
            MouseLook();
        }
        LookZRU();

    }
}


void CameraPosition(Transform target)
{
    if (activeTarget == false)  
    {
        transform.position = transform.localRotation * offset + target.position;
    }
        MouseLook();
    

}

void MouseLook()
{
    if (Input.GetAxis("Mouse ScrollWheel") > 0) offset.z += zoom;
    else if (Input.GetAxis("Mouse ScrollWheel") < 0) offset.z -= zoom;
    offset.z = Mathf.Clamp(offset.z, -Mathf.Abs(zoomMax), -Mathf.Abs(zoomMin));

    if (Input.GetMouseButton(1))
    {
        X = transform.localEulerAngles.y + Input.GetAxis("Mouse X") * sensitivity;
    }
    if (Input.GetMouseButton(0))
    {
        Y += Input.GetAxis("Mouse Y") * sensitivity;
    }
    Y = Mathf.Clamp(Y, -limit, limit);
    transform.localEulerAngles = new Vector3(-Y, X, 0);
}

void LookZRU()
{
    Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
    RaycastHit hit;

    if (Physics.Raycast(ray, out hit))
    {
        if (hit.collider.gameObject.GetComponent<SelectZRU>())
        {
            Debug.Log(gameObject.name + " бла бла");
            if (Input.GetKeyDown(KeyCode.R))
            {
                activeTarget = true;
                CameraPosition(lookZRU);
            }
        }
    }

    if (activeTarget == true)
    {
        MouseLook();
    }
}
over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

You can use rotate around, just update "obj" value with your new clicked object position.

Vector3 obj = target.transform.position; //change this
transform.RotateAround(obj, Vector3.up, 20 * Time.deltaTime);
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda