Hello everyone.
I’ve started programming with unity3D, so I am beginner and not really good. I tried to create a “Jump” button for an Android App, but everything I tried just failed. First I tried Input.touchCount, but then I could jump only one or endless times. Then I tried TouchPhase.began, but nothing happen if I click on the button. Finally I tried HitTest and again, nothing happen. I don’t know any other solution. Could you help me? Code:
using UnityEngine;
using System.Collections;
public class Jump : MonoBehaviour {
public bool var;
void Update()
{
foreach(Touch touch in Input.touches)
if(this.GetComponent<GUITexture>().HitTest(touch.position))
{
var = true;
}
}
}
(‘var’ is used in another script for jumping)
Thanks!
Hi well what I did here was have a Gameobject with a script called test
sing UnityEngine;
using System.Collections;
public class Test : MonoBehaviour {
public GameObject test ;
public bool toto;
// Use this for initialization
void Start ()
{
}
// Update is called once per frame
void Update ()
{
jump ();
//Debug.Log (toto);
}
public void cambiarBool()
{
if (toto) {
toto = false;
toto=true;
}
}
public void jump()
{
if (toto == false && Input.GetMouseButtonDown(0))
{
test.transform.Translate(Vector3.up );
}
}
}
That at the same time had a GameObject called Test that is the same gameobject , I referenced the GO just by dragging the GO from the Hierarchy view to the slot in the editor that whas created from the line of code "public GameObject test ; "( I like referencing GO like this) . Afterwards I created a UI.Button and in the button inspector I went to the On Click () property and below where you choose if you want (Off, editor and runetime and runetime) I referenced the gameobject that had the script Test . Next, next to the where you choose those options I listed before, you choose the script where you have your commands (in my case Test ) so I can access all the PUBLIC declared functions, in my case the cambiarBool (this in spanish means change bool) so I can afterwards proceed to jump. 
I kinda did something sloppy where my bool changes from true to false ( so a “trigger” event occurs) but also, made sure that to jump, the left mouse button had to be pressed at the same time because otherwise it would move up always.