Hi, I have been trying all sorts of code to make my character jump by tapping the screen. This is for an android device. I have no problems making everything work correctly in Xcode, I just an illogical inability to get things working for android devices.
Thanks in advance
1 Answer
1
this will manage each touch (up to five fingers depending on the device).
first off all there are 5 situations a Touchphase will face see here : 1251125
so you have to decide when the action should happen , when beginning touch, or …
here is a small example that will run whatever you want when the touch begins and if the touch not over five fingers or the user stopped touching:
void Update()
{
int fingerCount = 0;
foreach (Touch touch in Input.touches) {
if (touch.phase == TouchPhase.Began && touch.phase != TouchPhase.Canceled)
{
fingerCount++;
}
}
}
if (fingerCount > 0)
{
// manage the Vector or Force Manipulation here of the Player Prefab
}
Another Example where you manage if it is only 1 finger touching or 2 and so on:
using UnityEngine;
using System.Collections;
public class example : MonoBehaviour {
void Update() {
int fingerCount = 0;
foreach (Touch touch in Input.touches) {
if (touch.phase != TouchPhase.Ended && touch.phase != TouchPhase.Canceled)
fingerCount++;
}
if (fingerCount == 1)
{
print("User has " + fingerCount + " finger(s) touching the screen");
}else if (fingerCount ==2)
{
// do another thing if 2 fingers
}
}
}
hope this will help you to start solving your problem.
where are you facing troubles ,with recognizing the touches ? or adding the code to manage the physical action of the gameObject (adding some force in Y axis if it is pointing up) ?
– Graphicated