Touch screen Input Help
I've been stuck on this thing for two days, I tried everything I know I just can't to get it work
so here is my code
public GameObject shield;
bool canClink= true;
private float timetonextclick;
void Start () {
}
void Update () {
if (canClink == true && Input.GetMouseButtonDown (0)) {
GameObject myShield = (GameObject)Instantiate (shield, transform.position, Quaternion.identity);
CreateShield shieldScript = myShield.GetComponent<CreateShield> ();
shieldScript.myOwner = this.gameObject;
canClink = false;
timetonextclick = 0.0f;
}
if (canClink == false) {
timetonextclick += Time.deltaTime;
}
if (timetonextclick >= 10f) {
canClink = true;
}
}
}
}
In this code everything works fine, the mouse click works but when I try to convert the input into touch Screen it doesn't work can anyone please tell me how to insert the touch input instead of the mouse input and keeping the codes in the update so it keeps Re-spawn at each screen touch.
Answer by Bill9009 · Jun 21, 2017 at 08:44 PM
Replace:
if (canClink == true && Input.GetMouseButtonDown (0))
With:
if (canClink == true && Input.touchCount > 0 && Input.GetTouch(0).type == TouchType.Direct)
Edit: Sorry I've never used GetTouch() before, so i've changed it. I hope this works
It doesn't work
it says GetTouch() doesn't take 0 arguments and != can't be applied to GetTouch and
Your answer
Follow this Question
Related Questions
Why is my Camera not rotating properly? 1 Answer
Editing animation curves in a script 2 Answers
how do i rotate an object? C# 1 Answer
uNet. Spawning objects over the network. 0 Answers