Good day,
I am in the process of making a rhythm game. My first time trying touch capability in one of my games. Basically when the ‘notes’ spawn and I touch them some of them don’t register as hit even though I 100% hit them.
I tired counting to see if it every x note didn’t work but that wasn’t the case.
void Update()
{
foreach (Touch touch in Input.touches)
{
if (Input.touchCount >= 0 && Input.GetTouch(0).phase == TouchPhase.Began)
{
touchPosWorld = Camera.main.ScreenToWorldPoint(Input.GetTouch(0).position);
Vector2 touchPosWorld2D = new Vector2(touchPosWorld.x, touchPosWorld.y);
RaycastHit2D hitInformation = Physics2D.Raycast(touchPosWorld2D, Camera.main.transform.forward);
if (hitInformation.collider.tag != "Button")
{
GameObject touchedObject = hitInformation.transform.gameObject;
touchedObject.GetComponent<SpriteRenderer>().sprite = blank;
Instantiate(partRed, touchedObject.transform.position, Quaternion.identity);
partRed.Play();
}
}
}
**// 2nd touch..**
if (Input.touchCount > 0 && Input.GetTouch(1).phase == TouchPhase.Began)
{
touchPosWorld = Camera.main.ScreenToWorldPoint(Input.GetTouch(1).position);
Vector2 touchPosWorld2D = new Vector2(touchPosWorld.x, touchPosWorld.y);
RaycastHit2D hitInformation = Physics2D.Raycast(touchPosWorld2D, Camera.main.transform.forward);
if (hitInformation.collider.tag != "Button")
{
GameObject touchedObject1 = hitInformation.transform.gameObject;
touchedObject1.GetComponent<SpriteRenderer>().sprite = blank;
Instantiate(partRed, touchedObject1.transform.position, Quaternion.identity);
partRed.Play();
}
}
**// 3rd touch..**
if (Input.touchCount > 0 && Input.GetTouch(2).phase == TouchPhase.Began)
{
touchPosWorld = Camera.main.ScreenToWorldPoint(Input.GetTouch(1).position);
Vector2 touchPosWorld2D = new Vector2(touchPosWorld.x, touchPosWorld.y);
RaycastHit2D hitInformation = Physics2D.Raycast(touchPosWorld2D, Camera.main.transform.forward);
if (hitInformation.collider.tag != "Button")
{
GameObject touchedObject2 = hitInformation.transform.gameObject;
touchedObject2.GetComponent<SpriteRenderer>().sprite = blank;
Instantiate(partRed, touchedObject2.transform.position, Quaternion.identity);
partRed.Play();
}
}
}
The particles don’t won’t either but I posted that into another question on this board ;).
Thanks for your help.
Russell