Question by
Cratemaker82 · Nov 19, 2015 at 12:43 AM ·
c#scripting beginnerbeginnerjumpingsimple
How do you make your player jump in the Roll-a-Ball tutorial series?
Okay so I was wondering if there was a way to make your player bounce up (jump) in the Roll-a-Ball tutorial series. Can someone write out a C# script for me on how to jump up and go back down on the ground without having the ability to jump multiple times. I am super new to this scripting stuff so if anybody could make it easy for me I would very much appreciate that (please). Thanks!
This is what the player script looks like :
using UnityEngine; using UnityEngine.UI; using System.Collections;
public class PlayerController : MonoBehaviour {
public float speed;
public Text countText;
public Text winText;
private Rigidbody rb;
private int count;
void Start ()
{
rb = GetComponent<Rigidbody>();
count = 0;
SetCountText ();
winText.text = "";
}
void FixedUpdate ()
{
float moveHorizontal = Input.GetAxis ("Horizontal");
float moveVertical = Input.GetAxis ("Vertical");
Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
rb.AddForce (movement * speed);
}
void OnTriggerEnter(Collider other)
{
if (other.gameObject.CompareTag ( "Pick Up"))
{
other.gameObject.SetActive (false);
count = count + 1;
SetCountText ();
}
}
void SetCountText ()
{
countText.text = "Count: " + count.ToString ();
if (count >= 12)
{
winText.text = "You Win!";
}
}
}
Comment