third person shooter camera code unity unity3d
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMove : MonoBehaviour
{
private Camera mCamera;
// Start is called before the first frame update
void Start()
{
mCamera = transform.Find("PlayerCamera").GetComponent<Camera>();
}
// Update is called once per frame
void Update()
{
float x = Input.GetAxisRaw("Mouse X");
float y = Input.GetAxisRaw("Mouse Y");
//The offset of the mouse's x-axis, directly used to rotate the y-axis of the character
transform.Rotate(new Vector3(0, x, 0), Space.Self);
//Mouse y-axis offset, used to rotate the camera around the character's x-axis
mCamera.transform.RotateAround(transform.position,transform.right,-y);
}
}
1234567891011121314151617181920212223242526272829