Darkgamer3337
Darkgamer3337
CC#
Created by Darkgamer3337 on 11/17/2023 in #help
How can i fix this error code?
ok every thing works now, thank you
19 replies
CC#
Created by Darkgamer3337 on 11/17/2023 in #help
How can i fix this error code?
in the player class?
19 replies
CC#
Created by Darkgamer3337 on 11/17/2023 in #help
How can i fix this error code?
No description
19 replies
CC#
Created by Darkgamer3337 on 11/17/2023 in #help
How can i fix this error code?
just a simple script for a 2d character
19 replies
CC#
Created by Darkgamer3337 on 11/17/2023 in #help
How can i fix this error code?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

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;


public class player : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{

}

// Update is called once per frame
void Update()
{
horizontal = Input.GetAxisRaw("Horizontal");

if (Input.GetButtonDown("Jump") && IsGroundedGrounded())
{
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;
trasform.localScale = localScale;
}
}


}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

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;


public class player : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{

}

// Update is called once per frame
void Update()
{
horizontal = Input.GetAxisRaw("Horizontal");

if (Input.GetButtonDown("Jump") && IsGroundedGrounded())
{
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;
trasform.localScale = localScale;
}
}


}
19 replies
CC#
Created by Darkgamer3337 on 11/17/2023 in #help
How can i fix this error code?
do you need anything else?
19 replies
CC#
Created by Darkgamer3337 on 11/17/2023 in #help
How can i fix this error code?
im new so i dont really know how tofix this
19 replies
CC#
Created by Darkgamer3337 on 11/17/2023 in #help
How can i fix this error code?
No description
19 replies