Hi there! Am new to programming (so far i have under a week of experience) and i’ve encountered a issue with my code(the error posted in the title).
Mind you i am following tutorials in an attempt on learning unity and i am trying to implement wall running into my game by following the steps shown in this video:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMotor : MonoBehaviour
{
private CharacterController controller;
private state;
private Vector3 playerVelocity;
private bool isGrounded;
public float speed = 5f;
public float gravity = -9.8f;
public float jumpHeight = 3f;
private bool sprinting;
public float crouchTimer;
private bool lerpCrouch;
private bool crouching;
public float wallrunSpeed;
public bool wallrunning;
public float moveSpeed;
public enum MovementState
{
walking,
sprinting,
wallrunning,
crouching,
}
// Start is called before the first frame update
void Start()
{
controller = GetComponent<CharacterController>();
}
// Update is called once per frame
void Update()
{
isGrounded = controller.isGrounded;
if (lerpCrouch)
{
crouchTimer += Time.deltaTime;
float p = crouchTimer / 1;
p *= p;
if (crouching)
controller.height = Mathf.Lerp(controller.height, 1, p);
else
controller.height = Mathf.Lerp(controller.height, 2, p);
if (p > 1)
{
lerpCrouch = false;
crouchTimer = 0f;
}
}
}
public void ProcessMove(Vector2 input)
{
Vector3 moveDirection = Vector3.zero;
moveDirection.x = input.x;
moveDirection.z = input.y;
controller.Move(transform.TransformDirection(moveDirection) * speed * Time.deltaTime);
playerVelocity.y += gravity * Time.deltaTime;
if (isGrounded && playerVelocity.y < 0)
playerVelocity.y = -2f;
controller.Move(playerVelocity * Time.deltaTime);
Debug.Log(playerVelocity.y);
}
public void Jump()
{
if(isGrounded)
{
playerVelocity.y = Mathf.Sqrt(jumpHeight * -3.0f * gravity);
}
}
public void Crouch()
{
crouching = !crouching;
crouchTimer = 0;
lerpCrouch = true;
}
public void Sprint()
{
sprinting = !sprinting;
if (sprinting)
speed = 10;
else
speed = 15;
}
public void StateHandler()
{
//Mode - WallRunning
if (wallrunning)
{
state = MovementState.wallrunning;
moveSpeed = wallrunSpeed;
}
}
}