I tried to make a jumping script for the player, but it didn’t work because it didn’t match my PlayerMovement script. Anyways here’s my script:
using UnityEngine;
using UnityEngine.SceneManagement;
public class PlayerMovement : MonoBehaviour
{
bool alive = true;
public float speed = 5;
[SerializeField] Rigidbody rb;
float horizontalInput;
[SerializeField] float horizontalMultiplier = 2;
public float speedIncreasePerPoint = 0.1f;
private void FixedUpdate()
{
if (!alive) return;
Vector3 forwardMove = transform.forward * speed * Time.fixedDeltaTime;
Vector3 horizontalMove = transform.right * horizontalInput * speed * Time.fixedDeltaTime * horizontalMultiplier;
rb.MovePosition(rb.position + forwardMove + horizontalMove);
}
private void Update()
{
horizontalInput = Input.GetAxis(“Horizontal”);
if (transform.position.y < -5)
{
Die();
}
}
public void Die()
{
alive = false;
// Restart the game
Invoke(“Restart”, 0);
}
void Restart()
{
SceneManager.LoadScene(SceneManager.GetActiveScene().name);
}
}