Пример #1
0
    private IEnumerator PlayConfettis()
    {
        do
        {
            RectTransform confetti = Instantiate(confettis[UnityEngine.Random.Range(0, confettis.Length)], transform, false).GetComponent <RectTransform>();
            confetti.localPosition = new Vector3(UnityEngine.Random.Range(0f, Camera.main.pixelWidth) - Camera.main.pixelWidth / 2f, UnityEngine.Random.Range(0f, Camera.main.pixelHeight) - Camera.main.pixelHeight / 2f);
            confetti.eulerAngles   = new Vector3(UnityEngine.Random.Range(0f, 360f), confetti.eulerAngles.y, confetti.eulerAngles.z);

            confettiSounds.PlayRandomAudio(audioSource);

            float widthHeight = Camera.main.pixelHeight * UnityEngine.Random.Range(0.2f, 0.3f);
            confetti.localScale = new Vector3(widthHeight, widthHeight, widthHeight);

            yield return(new WaitForSeconds(UnityEngine.Random.value));
        } while (true);
    }
    public void OnPointerClick(PointerEventData eventData)
    {
        clickCount++;

        // We have broken the crate
        if (clickCount > crateCracks.Length)
        {
            return;
        }

        // We don't care if it breaks, do this everytime
        DOTween.Sequence()
        .Append(sunRayImage.rectTransform.DOScale(1.1f, shakeTime))
        .Append(sunRayImage.rectTransform.DOScale(1f, shakeTime));

        // Break
        if (clickCount == crateCracks.Length)
        {
            brokenParticle.Play(true);
            breakParticle.Play(true);

            crateImage.gameObject.SetActive(false);

            rewardImage.DOFade(1f, 0.2f);
            text.DOFade(1f, 0.2f);

            breakSound.PlayRandomAudio(audioSource);
            return;
        }
        crackSound.PlayRandomAudio(audioSource);

        crateImage.sprite = crateCracks[clickCount];

        crateImage.rectTransform.DOShakeAnchorPos(shakeTime, 30f, 8, 50f);
        crateImage.rectTransform.DOShakeRotation(shakeTime, new Vector3(0, 0, 40f), 10, 30f);

        breakParticle.Play(true);
    }