mnoktau
1
Hello everyone as you know, I have to introduce my jumping script to button, so here is my jumping script;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Jump : MonoBehaviour {
public bool onGround;
private Rigidbody rb;
void Start () {
onGround = true;
rb = GetComponent<Rigidbody> ();
}
void Update ()
{
if(onGround)
{
if(Input.GetButtonDown("Jump"))
{rb.velocity = new Vector3 (0f, 87f, 0f);
onGround = false;
}
}
}
void OnCollisionEnter (Collision other)
{
if (other.gameObject.CompareTag ("Ground")) {
onGround = true;
}
}
}
how can I do that? cuz, I searched, and I didn’t find.
josh15
2
//this here the player script
public bool onGround;
private Rigidbody rb;
public bool jump;
float jumping = 87f;
void Start()
{
onGround = true;
rb = GetComponent<Rigidbody>();
}
void Update()
{
if (onGround)
{
if (Input.GetButtonDown("Jump") )
{
jumpMethod()
}
}
}
public void jumpMethod()
{
rb.velocity = new Vector3(0f, jumping, 0f); onGround = false;
}
void OnCollisionEnter(Collision other)
{
if (other.gameObject.CompareTag("Ground"))
{
onGround = true;
}
}
//and here the button script
public void playerjump()
{
if( FindObjectOfType<player>().onGround == true)
{
FindObjectOfType<player>().jumpMethod();
}
}
that work with me hope it’s help

and this the button