jump-ball/09.09 Less_unity/Assets/Scripts/Jumping.cs
2024-09-11 10:54:13 +03:00

27 lines
578 B
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
//[RequireComponent(typeof(Rigidbody))] ;
public class Jumping : MonoBehaviour
{
[SerializeField] private float jumpForce;
//Start is called before the first frame update
private Rigidbody _rb;
private void Awake()
{
_rb = GetComponent<Rigidbody>();
}
//Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.Space))
{
_rb.AddForce(new Vector3(0, jumpForce, 0), ForceMode.Impulse);
}
}
}