Unity gives this error :
MissingComponentException: There is no ‘CharacterController’ attached to the “player” game object, but a script is trying to access it.
You probably need to add a CharacterController to the game object “player”. Or your script needs to check if the component is attached before using it.
UnityEngine.CharacterController.Move (Vector3 motion) (at C:/buildslave/unity/build/artifacts/generated/bindings_old/common/Physics/DynamicsBindings.gen.cs:3268)
FPSController.Update () (at Assets/FPSController.cs:36)
But i alreadyhave an component called player.
I have screenshot attachet .Can someone help me with this. my code is
using System.Collections;
using UnityEngine;
public class FPSController : MonoBehaviour {
public float speed = 2f;
public float sensitivity = 2f;
CharacterController player;
float moveFB;
float moveLR;
float rotX;
float rotY;
// Use this for initialization
void Start () {
player = GetComponent<CharacterController>();
}
// Update is called once per frame
void Update () {
moveFB = Input.GetAxisRaw("Vertical") * speed;
moveLR = Input.GetAxisRaw("Horizontal") * speed;
rotX = Input.GetAxis("Mouse X") * sensitivity;
rotY = Input.GetAxis("Mouse Y") * sensitivity;
Vector3 movement = new Vector3(moveLR, 0, moveFB);
transform.Rotate(0, rotX, 0);
movement = transform.rotation * movement;
player.Move(motion: movement * Time.deltaTime);
}
}