Object Control in Unity
Here I share my code as to how to rotate the object around, zoom in and out, and translate in the game environment. I think you could use a similar approach for your camera (I initially wanted to move the camera around, that's why the name), but you would need some tweaking around. Hope this can help!
P.S. : I might upload an update to explain my code, but now this should do :D
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class camera_movement : MonoBehaviour
{
[SerializeField] float rotate_sensitivity = 160f;
[SerializeField] float scale_sensitivity = 2f;
[SerializeField] float trans_sensitivity = 5f;
private void Update() {
if(Input.GetKey(KeyCode.A))
{
transform.RotateAround(transform.position, Vector3.up, rotate_sensitivity * Time.deltaTime);
}
else if(Input.GetKey(KeyCode.D))
{
transform.RotateAround(transform.position, Vector3.down, rotate_sensitivity * Time.deltaTime);
}
else if(Input.GetKey(KeyCode.W))
{
transform.RotateAround(transform.position, Vector3.right, rotate_sensitivity * Time.deltaTime);
}
else if(Input.GetKey(KeyCode.S))
{
transform.RotateAround(transform.position, Vector3.left, rotate_sensitivity * Time.deltaTime);
}
else if(Input.GetKey(KeyCode.Q))
{
transform.localScale += transform.localScale * scale_sensitivity * Time.deltaTime;
}
else if(Input.GetKey(KeyCode.E))
{
transform.localScale -= transform.localScale * scale_sensitivity * Time.deltaTime;
}
if(Input.GetKey(KeyCode.UpArrow))
{
transform.position += Vector3.up *trans_sensitivity * Time.deltaTime;
}
else if(Input.GetKey(KeyCode.DownArrow))
{
transform.position += Vector3.down * trans_sensitivity * Time.deltaTime;
}
else if(Input.GetKey(KeyCode.RightArrow))
{
transform.position += Vector3.right * trans_sensitivity * Time.deltaTime;;
}
else if(Input.GetKey(KeyCode.LeftArrow))
{
transform.position += Vector3.left * trans_sensitivity * Time.deltaTime;;
}
}
}
Leave a comment
Log in with itch.io to leave a comment.