The contents are as follows.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerContllor : MonoBehaviour
{
[SerializeField]
private float walkspeed;
private Rigidbody myRigid;
[SerializeField]
private float lookSensitivity;
[SerializeField]
private float cameraRotationLimit;
private float currentCameraRotationX = 0;
[SerializeField]
private Camera theCamera;
private Rigidbody myRigid;
// Start is called before the first frame update
void Start()
{
myRigid = GetComponent<Rigidbody>();
}
// Update is called once per frame
void Update()
{
Move();
CameraRotation();
}
private void Move()
{
float _moveDirX = Input.GetAxisRaw("Horizontal");
float _moveDirZ = Input.GetAxisRaw("Vertical");
Vector3 _moveHorizontal = transform.right * _moveDirX;
Vector3 _moveVertical = transform.forward * _moveDirZ;
Vector3 _velocity = (_moveHorizontal + _moveVertical).normalized * walkspeed;
myRigid.MovePosition(transform.position + _velocity * Time.deltaTime);
}
private void CameraRotation()
{
float _xRotation = Input.GetAxisRaw("Mouse Y");
float _cameraRotationX = _xRotation * lookSensitivity;
currentCameraRotationX += _cameraRotationX;
currentCameraRotationX = Mathf.Clamp(currentCameraRotationX, - cameraRotationLimit, cameraRotationLimit);
theCamera.transform.localEulerAngles = new Vector3(currentCameraRotationX, 0f, 0f);
}
}'''
I wrote this and got an error like this.
please help me avoid errors.
It is to implement the movement of the player and the movement of the character screen up and down with the mouse.
The content of the error is as follows.
unassigned Reference Exception: The variable theCamera of PlayerController has not been assigned. You probably need to assign theCamera variable of the playerController script in the inspector.
Thank you.