Quantcast
Channel: Questions in topic: "error message"
Viewing all articles
Browse latest Browse all 2891

error cs0103

$
0
0
i have the folowing error and im busy for over 3 hours trying to fix it but i can`t get it right error CS0103: The name 'characterController' does not exist in the current context my code: using System.Collections; using System.Collections.Generic; using UnityEngine; public class FirstPersonMovement : MonoBehaviour { private CharacterController characterController; public float moveSpeed = 10f; public float mouseSensitivity = 100f; public float jumpForce = 25f; public float gravity = -75f; public float terminalVelocity = -10f; public float jumpHeight = 2f; public float sprintMultiplier = 1.5f; public KeyCode forwardKey = KeyCode.W; public KeyCode backwardKey = KeyCode.S; public KeyCode leftKey = KeyCode.A; public KeyCode rightKey = KeyCode.D; public KeyCode jumpKey = KeyCode.Space; public KeyCode sprintKey = KeyCode.LeftShift; public float minPitch = -80f; public float maxPitch = 80f; private float verticalVelocity; private float currentSpeed; private bool isSprinting = false; void Start() { characterController = GetComponent(); } void Update() { float horizontal = Input.GetKey(rightKey) ? 1 : Input.GetKey(leftKey) ? -1 : 0; float vertical = Input.GetKey(forwardKey) ? 1 : Input.GetKey(backwardKey) ? -1 : 0; Vector3 moveDirection = new Vector3(horizontal, 0, vertical); moveDirection = Camera.main.transform.TransformDirection(moveDirection); moveDirection *= currentSpeed; float yaw = Input.GetAxis("Mouse X") * mouseSensitivity * Time.deltaTime; transform.Rotate(0, yaw, 0); if (Camera.main.transform.localEulerAngles.x > 180) { float x = Camera.main.transform.localEulerAngles.x - 360; if (x < maxPitch && x > minPitch) { float pitch = -Input.GetAxis("Mouse Y") * mouseSensitivity * Time.deltaTime; Camera.main.transform.localEulerAngles += new Vector3(pitch, 0, 0); } } else { if (Camera.main.transform.localEulerAngles.x < maxPitch && Camera.main.transform.localEulerAngles.x > minPitch) { float pitch = -Input.GetAxis("Mouse Y") * mouseSensitivity * Time.deltaTime; Camera.main.transform.localEulerAngles += new Vector3(pitch, 0, 0); } } if (characterController.isGrounded) { verticalVelocity = -0.5f; if (Input.GetKey(jumpKey)) { if (verticalVelocity < jumpForce) { verticalVelocity = jumpForce; } } } else { verticalVelocity += gravity * Time.deltaTime; if (verticalVelocity < terminalVelocity) { verticalVelocity = terminalVelocity; } } moveDirection.y = verticalVelocity; characterController.Move(moveDirection * Time.deltaTime); if (Input.GetKey(sprintKey) && !isSprinting && characterController.isGrounded) { isSprinting = true; currentSpeed *= sprintMultiplier; } else if (Input.GetKeyUp(sprintKey) && isSprinting) { isSprinting = false; currentSpeed /= sprintMultiplier; } } } if anyone can help it would be amazing thank you to the one who can fix it

Viewing all articles
Browse latest Browse all 2891

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>