I’m new to coding and I’m following a youtube tutorial. I need help with this code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class a : StateMachineBehaviour
{
private float horizontal;
private float speed = 8f;
private float jumpingPower=16f;
private bool isFacingRight=true;
[SerializeField] private Rigidbody2D rb;
[SerializeField] private Transform groundCheck;
[SerializeField] private LayerMask groundlayer;
void Update()
{
horizontal = Input.GetAxisRaw(“horizontal”);
if (Input.GetButtonDown(“Jump”) && IsGrounded())
{
rb.velocity = new Vector2(rb.velocity.x, jumpingPower);
}
if (Input.GetButtonUp(“Jump”) && rb.velocity.y > 0f)
{
rb.velocity = new Vector2(rb.velocity.x, rb.velocity.y * 0.5f);
}
Flip();
}
private void FixedUpdate()
{
rb.velocity = new Vector2(horizontal * speed, rb.velocity.y);
}
private bool IsGrounded()
{
return Physics2D.OverlapCircle(groundCheck.position, 0.2f, groundlayer);
}
private void Flip()
{
if (isFacingRight && horizontal < 0f || !isFacingRight && horizontal > 0f)
{
isFacingRight = !isFacingRight;
Vector3 localScale = transform.localScale;
localScale.x *= -1f;
transform.localScale = localScale;
}
}
}
(if you guys make any changes pls do the whole code in there as well so I can just copy and paste it back in.)
submitted by /u/Spamton1997_pipis
[link] [comments]
Unity2D – Develop 2D games using Unity