}// End of Update method // Checks collision between user hand and ducks. private void OnTriggerEnter2D(Collider2D collision) { // Gets component of left duck (duck which moving left direction). DuckLT duckLT = collision.gameObject.GetComponent <DuckLT>(); // Gets component of right duck (duck which moving right direction). DuckRT duckRT = collision.gameObject.GetComponent <DuckRT>(); // if the object is collected then give the boolean a value of true if (collision.gameObject.CompareTag("DuckLT") || collision.gameObject.CompareTag("DuckRT")) { // Increase score when detecting collision between hand and duck. duckManager.AddScore(scoreValue); isDuckDestroyed = true; if (collision.gameObject.CompareTag("DuckLT")) { Debug.Log("COLLISION LEFT HAND"); // Destroy left duck. StartCoroutine(duckLT.DestroyDucks()); } if (collision.gameObject.CompareTag("DuckRT")) { Debug.Log("COLLISION RIGHT HAND"); // Destroy right duck. StartCoroutine(duckRT.DestroyDucks()); } } }// End of OnTriggerEnter2D method.
private IEnumerator CreateDucks() { while (allDucksLT.Count < 2 || allDucksRT.Count < 2) { // Create and add the ducks // Left GameObject newDuckObjLeft = Instantiate(leftDuckPrefab, GetPlanePositionLeft(), Quaternion.identity, transform); DuckLT newDuckLeft = newDuckObjLeft.GetComponent <DuckLT>(); // Right // Create and add the ducks GameObject newDuckObjRight = Instantiate(rightDuckPrefab, GetPlanePositionRight(), Quaternion.identity, transform); DuckRT newDuckRight = newDuckObjRight.GetComponent <DuckRT>(); // Set up Ducks // Left newDuckLeft.mDuckManager = this; allDucksLT.Add(newDuckLeft); // Right newDuckRight.mDuckManager = this; allDucksRT.Add(newDuckRight); yield return(new WaitForSeconds(5f)); } }