- Home /
Question by
Content1of_akind · Apr 12, 2019 at 08:45 PM ·
unity 2dtouchframetouchphaseoneshot
How to make touch one frame in a 2D unity Game?
// When I put this code in, it does multiple frames at a time.
// I rather the code occur once instead of multiple times
// Thank you for you help =)
if(Input.TouchCount == 1)
{
if(Input.GetTouch(0).phase == TouchPhase.Began)
{
}
}
Comment
Best Answer
Answer by highpockets · Apr 12, 2019 at 09:13 PM
bool touchBegan = false;
void Update() {
if(Input.TouchCount == 1)
{
if(Input.GetTouch(0).phase == TouchPhase.Began && !touchBegan)
{
touchBegan = true;
}
if(TouchPhase.Ended || TouchPhase.Moved){
touchBegan = false;
}
}}
That should do it.
It works! Thank you. $$anonymous$$y issue was staying away from bool for a while because the way I used it caused multiple frames to take place. Thank you for the help!
No prob. Glad to help. Please mark the answer as correct to resolve the question. Cheers
Your answer
