Hello I want to implement tap to start the level on android. Here is my code couldn’t figure out whats wrong.
#pragma strict
function Start () {
//Tap to start
if(RuntimePlatform.Android) {
Time.timeScale = 0;
//render tap to start sprite
renderer.enabled = true;
if(Input.touchCount >= 1 && Input.GetTouch(0).phase == TouchPhase.Began) {
Time.timeScale = 1;
renderer.enabled = false;
}
}
}
function Update () {
}
Well it depends, If you want it to be anywhere then just use
function Update ()
{
if (Input.touchCount >= 1)
{
//Do something
}
}
If you want it to be a specific part like lets say when you touch a graphic layer text or texture
function Update ()
{
if (Input.touchCount > 0 )
{
for(var i : int = 0; i< Input.touchCount;i++)
{
var touch : Touch = Input.GetTouch(i);
if(touch.phase == TouchPhase.Began && guiTexture.HitTest(touch.position))
{
guiTexture.enabled = false;
//Do Something
}
}
}
}
Else if you want to detect if it is in a quadrent of the scene then this
NOTE: this cehcks the top right quater of the screen
var areaToTouch : Rect;
function Update ()
{
areaToTouch = Rect(Screen.width / 2, Screen.height / 2, Screen.height / 2, Screen.height / 2);
if (Input.touchCount > 0 )
{
for(var i : int = 0; i< Input.touchCount;i++)
{
var touch : Touch = Input.GetTouch(i);
if(touch.phase == TouchPhase.Began && areaToTouch.Contains(touch.position))
{
//Do Something
Debug.Log("Touch");
}
}
}
}
Maylina
3
Use tap checking in Update method. Here you check tap just one time. So you are too late when pressing tap.