is there a way to type out a if Input.GetButton instead of a if Input.GetKet?
currently if i press “Space” my character jumps, but i made a button, now i want the player to jump if i press the button instead of the key.
I have linked the button to my script, but if i don’t have a Input.GetButton or something, my script will just loop through the update, is there a way to make a if Input.GetButton just like an if Input.GetKey?
I want to make the Character jump with a button press ( For an android game )
The script i have now:
using UnityEngine;
using System.Collections;
public class PlayerMovement : MonoBehaviour {
public float playerSpeed = 5.0f;
public float jumpheight = 5.0f;
public bool isFalling = false;
// Update is called once per frame
public void Update () {
if (Input.GetButton("Spring") && isFalling == false) {
isFalling = true;
transform.Translate (Vector3.up * jumpheight * Time.deltaTime);
GetComponent<Rigidbody> ().AddForce (Vector3.up * jumpheight, ForceMode.Impulse);
Debug.Log("test");
}
}
void OnCollisionEnter (Collision col)
{
isFalling = false;
}
public void timo2 () {
Debug.Log ("This one does work");
}
}
My button is called “Spring”, so if i press button Spring, it needs to jump, but it doesn’t work.
if i link it to public void named timo 2, the debug.log(“This one does work”) Does show up, so the button is working.
But why isn’t it working with the update ()?
i think something went wrong with this part of the code: if (Input.GetButton("Spring") && isFalling == false) {
After a quick test; it does not appear to be anything wrong with the code, so you might be correct that there is something wrong with the “GetButton(“Spring”)” part of it.
Because I have not worked with Unity in Android, I cannot help any further than just to confirm the code works if you use a GetKey(KeyCode.Space) and press space to jump. Sorry I couldn’t be of any help :S
It’s not specific for android, just in general, even if i press the button within unity itself, it doesn’t work too weird enough, however the button does link to the script right because if i link it to the debug.log, the log does show up in the console.
Okay it’s fixed! somehow the problem was the update, instead op public void Update (), i typed: public void timo (), and that was the point, it’s not supposed to be in the update!