I see a couple of issues with the code you provided. Firstly, there are two Update() methods defined in the PlayerController class, which is not allowed. To fix this, you can combine the functionality of both methods into a single Update() method.
Secondly, there seems to be a duplicate variable named Update() in the updated code. You can remove it since it is causing a duplicate member definition.
Here's the updated code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Platformer.Gameplay;
using static Platformer.Core.Simulation;
using Platformer.Model;
using Platformer.Core;
namespace Platformer.Mechanics
{
public class PlayerController : KinematicObject
{
public AudioClip jumpAudio;
public AudioClip respawnAudio;
public AudioClip ouchAudio;
public float maxSpeed = 7;
public float jumpTakeOffSpeed = 7;
public JumpState jumpState = JumpState.Grounded;
private bool stopJump;
public Collider2D collider2d;
public AudioSource audioSource;
public Health health;
public bool controlEnabled = true;
bool jump;
Vector2 move;
SpriteRenderer spriteRenderer;
public Animator animator;
readonly PlatformerModel model = Simulation.GetModel<PlatformerModel>();
public Bounds Bounds => collider2d.bounds;
void Awake()
{
health = GetComponent<Health>();
audioSource = GetComponent<AudioSource>();
collider2d = GetComponent<Collider2D>();
spriteRenderer = GetComponent<SpriteRenderer>();
animator = GetComponent<Animator>();
}
protected override void Update()
{
if (controlEnabled)
{
move.x = Input.GetAxis("Horizontal");
if (jumpState == JumpState.Grounded && Input.GetButtonDown("Jump"))
jumpState = JumpState.PrepareToJump;
else if (Input.GetButtonUp("Jump"))
{
stopJump = true;
Schedule<PlayerStopJump>().player = this;
}
}
else
{
move.x = 0;
}
UpdateJumpState();
base.Update();
}
void UpdateJumpState()
{
jump = false;
switch (jumpState)
{
case JumpState.PrepareToJump:
jumpState = JumpState.Jumping;
jump = true;
stopJump = false;
break;
case JumpState.Jumping:
if (!IsGrounded)
{
Schedule<PlayerJumped>().player = this;
jumpState = JumpState.InFlight;
}
break;
case JumpState.InFlight:
if (IsGrounded)
{
Schedule<PlayerLanded>().player = this;
jumpState = JumpState.Landed;
}
break;
case JumpState.Landed:
jumpState = JumpState.Grounded;
break;
}
}
private Rigidbody2D rb;
private int extraJump;
public int extraJumpValue;
public float jumpForce;
private bool isGrounded;
public Transform point;
public float checkRadius;
public LayerMask groundLayer;
void Start()
{
extraJump = extraJumpValue;
rb = GetComponent<Rigidbody2D>();
}
protected override void ComputeVelocity()
{
isGrounded = Physics2D.OverlapCircle(point.position, checkRadius, groundLayer);
if (isGrounded == true)
{
extraJump = extraJumpValue;
}
if (jump && isGrounded == true)
{
rb.velocity = Vector2.up * jumpForce;
jump = false;
}
else if (Input.GetKeyDown(KeyCode.Space) && extraJump > 0)
{
rb.velocity = Vector2.up * jumpForce;
extraJump--;
}
if (move.x > 0.01f)
spriteRenderer.flipX = false;
else if (move.x < -0.01f)
spriteRenderer.flipX = true;
animator.SetBool("grounded", IsGrounded);
animator.SetFloat("velocityX", Mathf.Abs(velocity.x) / maxSpeed);
targetVelocity = move * maxSpeed;
}
public enum JumpState
{
Grounded,
PrepareToJump,
Jumping,
InFlight,
Landed
}
}
}
I hope this helps! Let me know if you have any further issues.