Hello! I was trying to code an FPS game made by @NattyCreations but I got an error on line 13 saying CharacterController is a type but is used like a variable. Can anyone help me? Here is my code using System.Collections; using System.Collections.Generic; using UnityEngine; public class PlayerMotor : MonoBehaviour { private CharacterController controller; private Vector3 playerVelocity; public float speed = 5f; // Start is called before the first frame update void Start() { CharacterController = GetComponent<CharacterController>(); <------- ERROR } // Update is called once per frame void Update() { } //recieve the inputs for your INputManager.cs and apply them to our character controller. public void ProcessMove(Vector2 input) { Vector3 moveDirection = Vector3.zero; moveDirection.x = input.x; moveDirection.z = input.y; CharacterController.Move(transform.TransformDirection(moveDirection) * speed * time.deltaTime); } }
You're trying to use the type name where you should be using your variable. Correct code: controller = GetComponent<CharacterController>(); You also have the same problem here: CharacterController.Move(transform.TransformDirection(moveDirection) * speed * time.deltaTime); It should be: controller.Move(transform.TransformDirection(moveDirection) * speed * time.deltaTime);
Also, here's how to post code on these forums: https://forum.unity.com/threads/using-code-tags-properly.143875/ Thanks.