private void OnTriggerEnter2D(Collider2D other) { EggDrag egg = other.GetComponent <EggDrag>(); // What collides it's an egg and also comes from the upper-left if (egg != null && (other.transform.position.x < transform.position.x && other.transform.position.y > transform.position.y)) { minigame.CrackEgg(egg); // Disable border for some time ('crackCooldown') GetComponent <Collider2D>().enabled = false; StartCoroutine(DoAfter(crackCooldown, () => { GetComponent <Collider2D>().enabled = true; })); } }
public void CrackEgg(EggDrag egg) { // Increase the number of cracks performed cracks++; // Change the sprite to the next state and play animation egg.GetComponentInChildren <SpriteRenderer>().sprite = eggSprites[Math.Min(cracks, eggSprites.Length - 1)]; egg.GetComponentInChildren <SpriteRenderer>().transform.localEulerAngles = new Vector3(0, 0, 90); // The cracked sprite is originally rotated, so we need to correct it egg.GetComponent <Animator>().Play("Animation"); // If the player performed the cracks needed, end the dragging phase if (cracks == cracksNeeded) { draggingPhase = false; blockCalls = true; egg.CancelDrag(); egg.GetComponent <Animator>().enabled = false; pointer.Hide(); // Translate and rotate the egg to the hover position egg.MoveAndRotateTo(hoverMarkTarget.position, 90, true, EnableCrackedEgg); pointer.Hide(); AkSoundEngine.PostEvent("Egg_Tap", gameObject); //StartEggCrackHandsAnimation(); // Hide the prompt and set the content once it's not visible promptControl.Hide(() => { promptControl.content = promptContents[1]; promptContents[0].SetActive(false); promptContents[1].SetActive(true); // Open prompt again and play animation when visible promptControl.Show(promptControl.PlayAnimations); }); } }