- Home /
touch input became enabled from the entire screen
Sorry for the question, I can't come up with a better one. Btw I am creating an AR android app, and I have this 3D model that when touched will play animation. I disabled its touch function while the voice clip is not yet ended and enabled it after that along with the animation back from idle. The problem is after that scenario had finished playing, if I touch anywhere on the screen, the model will then begin to animate. Which this is what I didn't wanted because I had it only animate when the model is touch, not anywhere on the screen.
Here is what I've done so far.
void Update() { if (!EventSystem.current.IsPointerOverGameObject ()) { if (EnableInput) { var mouseclick = Input.GetMouseButton (0); if (mouseclick) {
Vector3 mousePosFar = new Vector3 (Input.mousePosition.x, Input.mousePosition.y, Camera.main.farClipPlane);
Vector3 mousePosNear = new Vector3 (Input.mousePosition.x, Input.mousePosition.y, Camera.main.nearClipPlane);
Vector3 mousePosF = Camera.main.ScreenToWorldPoint (mousePosFar);
Vector3 mousePosN = Camera.main.ScreenToWorldPoint (mousePosNear);
RaycastHit hit;
if (Physics.Raycast (mousePosN, mousePosF - mousePosN, out hit))
model = hit.transform.name;
{
if (model == "Kuneho")
{
Ka.Play ("K_talk");
AS.clip = voiceclips [0];
AS.Play ();
StartCoroutine (audioEnded ());
//bc.enabled = false;
}
}
}
}
}
}
IEnumerator audioEnded()
{
EnableInput = false;
yield return new WaitUntil(() => !AS.isPlaying);
Ka.Play("K_idle");
EnableInput = true;
}
I used GetMouseButton but will change to TouchCount before building to android.
The touch works well at first where nothing happens if I touch anywhere on the screen except the model, but after clicking the model it will play its animation when I touch anywhere in the screen.
Sorry for the redundant and excessive use of word touch
Answer by summerian · Nov 05, 2018 at 12:51 PM
instead of raycast you can try OnMouseUpAsButton
yep. I'm using it myself for both iOS and Android
Answer by jessie_embiado · Nov 08, 2018 at 09:20 AM
How can I use the OnMouseUpAsButton thing? I can't find it in Input command.