Answers for "unity c# jump"

C#
11

unity how to make jump script

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

public class jump : MonoBehaviour
{
    public float jumpHeight = 7f;
    public bool isGrounded;
    public float NumberJumps = 0f;
    public float MaxJumps = 2;
    private Rigidbody rb;

    void Start()
    {
        rb = GetComponent<Rigidbody>();
    }

    void Update()
    {
        if (NumberJumps > MaxJumps - 1)
        {
            isGrounded = false;
        }

        if (isGrounded)
        {
            if (Input.GetButtonDown("Jump"))
            {
                rb.AddForce(Vector3.up * jumpHeight);
                NumberJumps += 1;
            }
        }
    }

    void OnCollisionEnter(Collision other)
    {
        isGrounded = true;
        NumberJumps = 0;
    }
    void OnCollisionExit(Collision other)
        {
            
    }
}
Posted by: Guest on January-15-2020
0

unity c# jump

public int forceConst = 50;  
private bool canJump; 
private RigidBody selfRigidbody;  

void Start()selfRigidbody = GetComponent<RigidBody>(); }  

void FixedUpdate(){ if(canJump){         
  canJump = false;     
  selfRigidbody.addForce(0, forceConst, 0, ForceMode.Impulse);    
} }  

void Update(){ if(Input.GetKeyUp(Keycode.SPACE)){  canJump = true;     } }
Posted by: Guest on May-28-2021

C# Answers by Framework

Browse Popular Code Answers by Language