Mail.ruПочтаМой МирОдноклассникиВКонтактеИгрыЗнакомстваНовостиКалендарьОблакоЗаметкиВсе проекты

Не работает скрипт прыжка юнити

Кирилл Бычихин Ученик (94), открыт 2 недели назад
Вот скрипт
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerMovement : MonoBehaviour
{
public float moveSpeed = 5f;
public float jumpForce = 10f;
private Rigidbody2D rb;
private bool isGrounded;
private Transform groundCheck;

void Start()
{
rb = GetComponent<Rigidbody2D>();
groundCheck = transform.Find("GroundCheck");
if (groundCheck == null)
{
Debug.LogError("GroundCheck not found!");
}
}

void Update()
{
isGrounded = Physics2D.OverlapCircle(groundCheck.position, 0.2f, LayerMask.GetMask("Ground"));

float moveInput = Input.GetAxis("Horizontal");
rb.velocity = new Vector2(moveInput * moveSpeed, rb.velocity.y);

if (isGrounded && Input.GetButtonDown("Jump"))
{
Jump();
}

if (moveInput > 0)
{
transform.localScale = new Vector3(1, 1, 1);
}
else if (moveInput < 0)
{
transform.localScale = new Vector3(-1, 1, 1);
}
}

void Jump()
{
rb.velocity = new Vector2(rb.velocity.x, 0);
rb.AddForce(new Vector2(0, jumpForce), ForceMode2D.Impulse);
}
}
0 ответов
Похожие вопросы