В чём ошибка кода почему персонаж не прыгает??? Жму W , а он не прыгает! Буду благодарен за советы по решению проблемы!
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Controller : MonoBehaviour
{
int speed = 2;
int jump = 10;
Rigidbody2D rb;
bool ground = false;
void Start()
{
rb = GetComponent<Rigidbody2D>();
}
// Update is called once per frame
void Update()
{
rb.velocity = new Vector2(Input.GetAxis("Horizontal") * speed, rb.velocity.y);
if(ground == true && Input.GetKeyDown(KeyCode.W))
rb.AddForce(transform.up * jump,ForceMode2D.Impulse);
}
private void OnCollisionEnter2D(Collision2D collision)
{
if(collision.gameObject.tag == "ground")
ground = true;
}
private void OnCollisionExit2D(Collision2D collision)
{
if(collision.gameObject.tag == "ground")
ground = false;
}
}