I have 2 2D gameobjects in unity.I want to achieve next but only with Input.GetTouch for android:
Problem is because I dont want to play sound from first case if object is dragging. I already tried some code with couroutine but it doesnt work:
if (Input.touchCount > 0) {
touch = Input.GetTouch(0);
touchPos = Camera.main.ScreenToWorldPoint(touch.position);
RaycastHit2D hit = Physics2D.Raycast(touchPos, Camera.main.transform.forward);
switch (touch.phase) {
case TouchPhase.Began:
samoKlik = true;
if (samoKlik) {
StartCoroutine(korotinaKlika());
}
}
case TouchPhase.Moved:
isMoved = true;
if (!samoKlik) {
if (jedan) {
break;
case TouchPhase.Ended:
isMoved = false;
jedan = false;
break;
}
You need to write your switch case properly. This code will not compile. The proper switch case syntac would be somethink like the one described here:
switch (touch.phase) {
case TouchPhase.Began:
samoKlik = true;
//if (samoKlik) { // This is not needed
StartCoroutine(korotinaKlika());
//}
break;
case TouchPhase.Moved:
isMoved = true;
if (!samoKlik) { // samoKlik does not exist here
if (jedan) {
break;
}
}
break;
case TouchPhase.Ended:
isMoved = false;
jedan = false;
break;
}
Since you want to fall from one conditional to another, it looks like the switch statement is not right for you.
I would suggest to try the following:
bool samoKlik = false;
bool isMoved = false;
bool jedan = false;
I can identify one for you to help you going
if (touch.phase == touchPhase.Moved && !samoKlik && jedan)