How do i make the ball jump with unity 3d pro , for a rolling ball game ? when i press the key space , on the keyboard ?
Input.GetKeyDown to detect a key press. Rigidbody.AddForce to make something “jump”.
Please also follow the tutorials, read the documentation, and search before asking a question - this is really basic stuff and you won’t get very far unless you understand it.
Follow these steps:
-
Create a Sphere from GameObject>Create Other>Sphere
-
Add RigidBody
3)Create c# script Jump:
using UnityEngine;
using System.Collections;
public class Jump : MonoBehaviour {
public float jump;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (Input.GetKeyDown (KeyCode.Space )){
this.rigidbody.AddForce(new Vector3(0,jump,0));
}
}
}
- Add Script Jump
5)Set value of jump 5000
6)Test it