The full error messages are:
(139, 18) error CS0176: Member ‘PlayerMovement.PlayerState.idle’ cannot be accessed with an instance reference, qualify it with a type name instead.
and
(117,10) error CS0161: ‘PlayerMovement’CheckFloorRays(Vector3)’: not all code paths return a value.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
public float gravity;
public float jumpVelocity;
public LayerMask floorMask;
public LayerMask wallMask;
public Vector2 velocity;
private bool grounded = false;
private bool walk, walk_left, walk_right, jump;
private PlayerState playerState = PlayerState.idle;
public enum PlayerState{
jumping,
idle,
walking
}
// Start is called before the first frame update
void Start()
{
// Fall ();
}
// Update is called once per frame
void Update()
{
CheckPlayerInput();
UpdatePlayerPosition();
}
void UpdatePlayerPosition() {
Vector3 pos = transform.localPosition;
Vector3 scale = transform.localScale;
if (walk) {
if (walk_left) {
pos.x -= velocity.x * Time.deltaTime;
scale.x = -1;
}
if (walk_right) {
pos.x += velocity.x * Time.deltaTime;
scale.x = 1;
}
pos = CheckWallRays (pos, scale.x);
}
if (jump && playerState != PlayerState.jumping) {
playerState = PlayerState.jumping;
velocity = new Vector2(velocity.x, jumpVelocity);
}
if (playerState == PlayerState.jumping) {
pos.y += velocity.y * Time.deltaTime;
velocity.y -= gravity * Time.deltaTime;
}
if (velocity.y <= 0)
pos = CheckFloorRays (pos);
transform.localPosition = pos;
transform.localScale = scale;
}
void CheckPlayerInput(){
bool Input_left = Input.GetKey(KeyCode.A);
bool Input_right = Input.GetKey(KeyCode.D);
bool input_space = Input.GetKeyDown(KeyCode.Space);
walk = Input_left || Input_right;
walk_left = Input_left && !Input_right;
walk_right = !Input_left && Input_right;
jump = input_space;
}
Vector3 CheckWallRays (Vector3 pos, float direction) {
Vector2 originTop = new Vector2 (pos.x + direction * .4f, pos.y + 1f - 0.2f);
Vector2 originMiddle = new Vector2 (pos.x + direction * .4f, pos.y);
Vector2 originBottom = new Vector2 (pos.x + direction * .4f, pos.y - 1f + 0.2f);
RaycastHit2D wallTop = Physics2D.Raycast (originTop, new Vector2 (direction, 0), velocity.x * Time.deltaTime, wallMask);
RaycastHit2D wallMiddle = Physics2D.Raycast (originMiddle, new Vector2 (direction, 0), velocity.x * Time.deltaTime, wallMask);
RaycastHit2D wallBottom = Physics2D.Raycast (originBottom, new Vector2 (direction, 0), velocity.x * Time.deltaTime, wallMask);
if (wallTop.collider != null || wallMiddle.collider != null || wallBottom.collider != null) {
pos.x -=velocity.x * Time.deltaTime * direction;
}
return pos;
}
Vector3 CheckFloorRays (Vector3 pos) {
Vector2 originLeft = new Vector2 (pos.x - 0.5f + 0.2f, pos.y - 1f);
Vector2 originMiddle = new Vector2 (pos.x, pos.y - 1f);
Vector2 originRight = new Vector2 (pos.x - 0.5f - 0.2f, pos.y - 1f);
RaycastHit2D floorLeft = Physics2D.Raycast (originLeft, Vector2.down, velocity.y * Time.deltaTime, floorMask);
RaycastHit2D floorMiddle = Physics2D.Raycast (originMiddle, Vector2.down, velocity.y * Time.deltaTime, floorMask);
RaycastHit2D floorRight = Physics2D.Raycast (originRight, Vector2.down, velocity.y * Time.deltaTime, floorMask);
if (floorLeft.collider != null || floorMiddle.collider !=null || floorRight.collider !=null) {
RaycastHit2D hitRay = floorRight;
if (floorLeft) {
hitRay = floorLeft;
} else if (floorMiddle){
hitRay = floorMiddle;
} else if (floorRight){
hitRay = floorRight;
}
playerState = playerState.idle;
grounded = true;
velocity.y = 0;
pos.y = hitRay.collider.bounds.center.y + hitRay.collider.bounds.size.y / 2 + 1;
}
}
void Fall () {
velocity.y = 0;
playerState = PlayerState.jumping;
grounded = false;
}
}
The lines playerState = playerState.idle; and Vector3 CheckFloorRays (Vector3 pos) { seem to be making the problem. Any helpful replies will be thanked