Something went wrong with my scrip, it keeps giving me (21,38) CS1002, (21,6) CS0270 and (21,5) CS0650.
I was using this tutorial
it was somewhere around the 6:00 minute mark something broke the code.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController1 : MonoBehaviour
{
[Header("Horizontal Movement Settings")]
private Rigidbody2D rb;
[SerializeField] private float walkSpeed = 1;
private float xAxis;
Animator anim;
public static PlayerController1 Instance;
PlayerStateList pState;
private int jumpBufferCounter = 0;
[SerializeField] private int jumpBufferFrames;
private float coyoteTimeCounter = 0;
[SerializeField]
private float coyoteTime
[Header("Ground Check Settings")]
[SerializeField] private float jumpForce = 10;
[SerializeField] private Transform groundCheckPoint;
[SerializeField] private float groundCheckY = 0.2f;
[SerializeField] private float groundCheckX = 0.5f;
[SerializeField] private LayerMask whatIsGround;
private void Awake()
{
if (Instance != null && Instance != this)
{
Destroy(gameObject);
}
else
{
Instance = this;
}
}
// Start is called before the first frame update
void Start()
{
pState = GetComponent<PlayerStateList>();
rb = GetComponent<Rigidbody2D>();
anim = GetComponent<Animator>();
}
// Update is called once per frame
void Update()
{
GetInputs();
UpdateJumpVariables();
Flip();
Move();
Jump();
}
void GetInputs()
{
xAxis = Input.GetAxisRaw("Horizontal");
}
void Flip()
{
if (xAxis < 0)
{
transform.localScale = new Vector2(-4, transform.localScale.y);
}
else if (xAxis > 0)
{
transform.localScale = new Vector2(4, transform.localScale.y);
}
}
private void Move()
{
rb.velocity = new Vector2(walkSpeed * xAxis, rb.velocity.y);
anim.SetBool("Walking", rb.velocity.x != 0 && Grounded());
}
public bool Grounded()
{
if (Physics2D.Raycast(groundCheckPoint.position, Vector2.down, groundCheckY, whatIsGround)
|| Physics2D.Raycast(groundCheckPoint.position + new Vector3(groundCheckX, 0, 0), Vector2.down, groundCheckY, whatIsGround)
|| Physics2D.Raycast(groundCheckPoint.position + new Vector3(-groundCheckX, 0, 0), Vector2.down, groundCheckY, whatIsGround))
{
return true;
}
else
{
return false;
}
}
void Jump()
{
if (Input.GetButtonDown("Jump") && rb.velocity.y > 0)
{
rb.velocity = new Vector2(rb.velocity.x, 0);
pState.jumping = false;
}
if (!pState.jumping)
{
if (jumpBufferCounter > 0 && Grounded())
{
rb.velocity = new Vector3(rb.velocity.x, jumpForce);
pState.jumping = true;
}
anim.SetBool("Jumping", !Grounded());
}
}
void UpdateJumpVariables()
{
if (Grounded())
{
pState.jumping = false;
}
if (Input.GetButtonDown("Jump"))
{
jumpBufferCounter = jumpBufferFrames;
}
else
{
jumpBufferCounter--;
}
}
}