Skip to content

ThirteeNov

My personal blog about coding and internet

Menu
  • About me
  • About Zofia Kreasi
  • Cart
  • Checkout
  • Making an airplane game from scratch in Unity
  • My account
  • Privacy Policy
  • Privacy Policy – zkLeaderboard
  • Sample Page
  • Shop
  • Tutorials on Learning JavaScript
  • ZKAccounts – Privacy Policy
Menu

Let’s Jump – A straightforward Unity C# script to make a Jump Button

Posted on August 26, 2020February 4, 2021 by Habibie

You have a capsule as your player placeholder, and you already added a rigid body to it. Then you need to make a jump button. What would you do?

Here using this simple script you can make a jump button for your character easily.

Attach this script to the capsule with rigid body in it, then make a button on UI Canvas, then drag and drop the capsule to the onclick slot, find startLetsJump() and that’s all.

Here is the script (please note, change && with && on line 27 and anywhere if you found it):

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

public class LetsJump : MonoBehaviour
{
	
	public float jumpSpeed = 3f;
	public float jumpDelay = 2f;
	
	private bool canjump;
	private bool isjumping;
    private Rigidbody rb;
	private float countDown;
	
    // Start is called before the first frame update
    void Start()
    {
        canjump = true;
		rb = GetComponent<Rigidbody>();
		countDown = jumpDelay;
    }

    // Update is called once per frame
    void Update()
    {
		if(isjumping && countDown > 0)
			countDown -= Time.deltaTime;
		else{
			canjump = true;
			isjumping = false;
			countDown = jumpDelay;
		}
			
    }
	
	public void StartLetsJump(){
		if(canjump){
			canjump = false;
			isjumping = true;
			rb.AddForce(0, jumpSpeed, 0, ForceMode.Impulse);
		}
	}
	
}

This script along a demonstration scene is included in a Unity package that you can download here: https://creativeshop.ciihuy.com/product/lets-jump-a-simple-way-to-jump-in-unity/

Easily download the package and import it to your Unity editor.

Post Views: 639
ciihuy2020

Welcome!

  • My YouTube Channel
  • My GitHub Page
  • About me

Categories

  • 3DVista
  • Android
  • Apache
  • C#
  • Cordova
  • Electron & Node JS
  • HTML5, CSS & JavaScript
  • iOS
  • Let's Make Unity Games
  • Misc
  • Photoshop
  • PHP
  • Python
  • Uncategorized
  • Unity
  • WordPress

Recent Posts

  • Hover Reveal script for Unity to show and hide object on mouse hover
  • How to Prevent UI Clicks in Unity from “Bleeding Through” to 3D Objects Behind Them
  • Make objects like wires and cables easily in Unity using Ciihuy Curved Mesh
  • [SOLVED] Can’t Add Custom Domain to Blogger After Losing CNAME Verification
  • iOS App Icon Generator by CiihuyCom
© 2026 ThirteeNov | Powered by Superbs Personal Blog theme