Hi Guys,
I have a 2 GUI Buttons one for moving my player and one for making my player jump.
my problem is that when i hold the move player button and i want to make my player jump and press the button my character stops. I want it so when i press my move button and my jump button my player jumps while moving.
Jump Button Script
using UnityEngine;
using System.Collections;
public class ButtonJump : MonoBehaviour {
public float JumpSpeed = 50f;
public bool grounded = true;
public Texture2D buttonImage = null;
// Use this for initialization
private void Start () {
}
// Update is called once per frame
private void Update () {
}
private void OnGUI(){
GUI.backgroundColor = new Color(0,0,0,0);
if (!grounded && rigidbody2D.velocity.y == 0) {
grounded = true;
}
if ((GUI.RepeatButton(new Rect(950,350,buttonImage.width,buttonImage.height), buttonImage)) && grounded == true) {
rigidbody2D.AddForce (transform.up * JumpSpeed);
grounded = false;
}
}
}
Move Button Script
using UnityEngine;
using System.Collections;
public class ButtonMove : MonoBehaviour {
public Texture2D buttonImage = null;
// Use this for initialization
private void Start () {
}
// Update is called once per frame
private void Update () {
}
private void OnGUI(){
GUI.backgroundColor = new Color(0,0,0,0);
if(GUI.RepeatButton(new Rect(150,350,buttonImage.width,buttonImage.height), buttonImage)){
transform.position += new Vector3(0.1f,0,0);
}
}
}
Thank You