Search Unity

Add X Rotation To This Orbit Script

Discussion in 'Scripting' started by Holocene, Apr 17, 2020.

  1. Holocene

    Holocene

    Joined:
    Feb 21, 2009
    Posts:
    347
    Hi,

    This orbit script is working well around one axis, but I'd like to add full 360º rotation.
    Any suggestions?

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. public class InputControl : MonoBehaviour
    5. {
    6.    public GameObject cameraOrbit;
    7.  
    8.    public float rotateSpeed = 8f;
    9.  
    10.    void Update()
    11.    {
    12.        if (Input.GetMouseButton(0))
    13.        {
    14.            float h = rotateSpeed * Input.GetAxis("Mouse X");
    15.            float v = rotateSpeed * Input.GetAxis("Mouse Y");
    16.  
    17.            if (cameraOrbit.transform.eulerAngles.z + v <= 0.1f || cameraOrbit.transform.eulerAngles.z + v >= 179.9f)
    18.                 v = 0;
    19.  
    20.            cameraOrbit.transform.eulerAngles = new Vector3(cameraOrbit.transform.eulerAngles.x, cameraOrbit.transform.eulerAngles.y + h, cameraOrbit.transform.eulerAngles.z + v);
    21.        }
    22.  
    23.        float scrollFactor = Input.GetAxis("Mouse ScrollWheel");
    24.  
    25.        if (scrollFactor != 0)
    26.        {
    27.            cameraOrbit.transform.localScale = cameraOrbit.transform.localScale * (1f - scrollFactor);
    28.        }
    29.  
    30.    }
    31. }