/// <summary> /// Captures the game update events to instantiate animals. /// </summary> private void Update() { if (TouchInput.IsTouchDown()) { touchingElapsedTime = 0; touchPosition = TouchInput.GetTouchPosition(); touchingSpawingArea = TouchInput.IsTouchingCollider(spawningArea, LayerMask.GetMask("Background")); animalDragged = GetTouchedAnimal(); if (animalDragged) { animalDragged.isBeingDragged = true; animalDragged.GetComponent <SpriteRenderer>().sortingOrder = 2; } } else if (TouchInput.IsTouching()) { touchingElapsedTime += Time.deltaTime; touchPosition = TouchInput.GetTouchPosition(); touchingSpawingArea = TouchInput.IsTouchingCollider(spawningArea, LayerMask.GetMask("Background")); if (!rope.Target && animalDragged && touchingElapsedTime >= draggingStartTime) { rope.Target = animalDragged.GetComponent <Rigidbody2D>(); } rope.transform.position = Camera.main.ScreenToWorldPoint(touchPosition); } else if (TouchInput.IsTouchUp()) { if (rope.Target) { rope.Target = null; } if (animalDragged) { animalDragged.isBeingDragged = false; animalDragged.GetComponent <SpriteRenderer>().sortingOrder = 0; } if (touchingSpawingArea && (!animalDragged || touchingElapsedTime < draggingStartTime)) { SpawnAnimal(); } } }
/// <summary> /// Gets the animal being touched. /// </summary> /// <returns>Returns the reference to the AnimalController of the animal /// being touched, or null if no animal has been touched.</returns> private AnimalController GetTouchedAnimal() { foreach (Transform child in transform) { AnimalController animal = child.GetComponent <AnimalController>(); if (animal && TouchInput.IsTouchingCollider(animal.GetComponent <PolygonCollider2D>(), LayerMask.GetMask("Animals"))) { return(animal); } } return(null); }
/// <summary> /// Captures the game update events to instantiate animals. /// </summary> private void Update() { if (TouchInput.IsTouchDown()) { touchingElapsedTime = 0; touchPosition = TouchInput.GetTouchPosition(); touchingSpawingArea = TouchInput.IsTouchingCollider(spawningArea, LayerMask.GetMask("Background")); animalDragged = GetTouchedAnimal(); if (animalDragged) { animalDragged.isBeingDragged = true; animalDragged.GetComponent <SpriteRenderer>().sortingOrder = 2; } } else if (TouchInput.IsTouching()) { touchingElapsedTime += Time.deltaTime; touchPosition = TouchInput.GetTouchPosition(); touchingSpawingArea = TouchInput.IsTouchingCollider(spawningArea, LayerMask.GetMask("Background")); if (animalDragged != null && touchingElapsedTime >= draggingStartTime) { Debug.Log("Incha e Explode: " + animalDragged.name); if (!inflating) { inflating = true; inflateTime = 0; StartCoroutine(InflateAndExplode(animalDragged.gameObject)); } } } else if (TouchInput.IsTouchUp()) { if (animalDragged) { animalDragged.isBeingDragged = false; animalDragged.GetComponent <SpriteRenderer>().sortingOrder = 0; } if (Time.time > inflateTime && touchingSpawingArea && (!animalDragged || touchingElapsedTime < draggingStartTime)) { SpawnAnimal(); } } }