本身寫的連擊文字特效

#region 處理連擊文字特效
    private float comboTimer=0.3f;
    private int comboNumber=0;
    private Coroutine comboCoroutine;

    protected GameObject comboPrefab;
    protected Transform[] comboNumberTransforms;
    protected Transform comboNumberTransform;
    protected SpriteRenderer[] comboNumberSprites;
    protected SpriteRenderer comboHit;
    protected Animator comboAnimator;
    /// <summary>
    /// 播放連擊動畫
    /// </summary>
    public void PlayComboEffect()
    {
        comboNumber += 1;
        if (comboCoroutine != null)
        {
            StopCoroutine(comboCoroutine);
        }
        comboCoroutine = StartCoroutine(CountComboNumber());
      
        comboAnimator.SetBool("ComboAni",true);
        InitNunber(comboNumber);
    }

    private IEnumerator CountComboNumber()
    {
        
        yield return new WaitForSeconds(comboTimer);
        comboNumber = 0;
        InitNunber(comboNumber);
    }


    void InitNunber(int level)
    {     
        if (level==0)
        {
            comboNumberTransforms[1].GetComponent<SpriteActive>().SetDeActive();
            comboNumberTransforms[2].GetComponent<SpriteActive>().SetDeActive();
            comboNumberTransforms[3].GetComponent<SpriteActive>().SetDeActive();
            comboHit.sprite = null;
        }
        if (level==1)
        {
            comboNumberTransforms[1].GetComponent<SpriteActive>().SetDeActive();
            comboNumberTransforms[2].GetComponent<SpriteActive>().SetDeActive();
            comboNumberTransforms[3].GetComponent<SpriteActive>().SetDeActive();

            comboHit.sprite = DataCenter.Instance.GameData.comboSprites.comboHitSprites[0];
        }
        if (level>1 && level < 10) //一位數
        {
            comboNumberTransforms[2].GetComponent<SpriteActive>().SetDeActive();
            comboNumberTransforms[3].GetComponent<SpriteActive>().SetDeActive();
           
            comboNumberSprites[0].sprite = DataCenter.Instance.GameData.comboSprites.comboNumberSprites[level];

            comboHit.sprite = DataCenter.Instance.GameData.comboSprites.comboHitSprites[1];
        }
        else if (level>=10 && level < 100) //二位數
        {            
            if (level==10)
            {
                comboNumberTransform.localPosition = new Vector3(comboNumberTransform.localPosition.x-0.25f,comboNumberTransform.localPosition.y,comboNumberTransform.localPosition.z);
            }

            comboNumberTransforms[3].GetComponent<SpriteActive>().SetDeActive();

            comboNumberSprites[0].sprite = DataCenter.Instance.GameData.comboSprites.comboNumberSprites[level/10];
            comboNumberSprites[1].sprite = DataCenter.Instance.GameData.comboSprites.comboNumberSprites[level%10];    

            comboHit.sprite = DataCenter.Instance.GameData.comboSprites.comboHitSprites[1];
        }
        else if (level>=100&&level <1000) //三位數
        { 
            if (level==100)
            {
                comboNumberTransform.localPosition = new Vector3(comboNumberTransform.localPosition.x-0.5f,comboNumberTransform.localPosition.y,comboNumberTransform.localPosition.z);
            }

            comboNumberSprites[0].sprite = DataCenter.Instance.GameData.comboSprites.comboNumberSprites[level/100];
            comboNumberSprites[1].sprite = DataCenter.Instance.GameData.comboSprites.comboNumberSprites[level/10%10]; 
            comboNumberSprites[2].sprite = DataCenter.Instance.GameData.comboSprites.comboNumberSprites[level%10]; 

            comboHit.sprite = DataCenter.Instance.GameData.comboSprites.comboHitSprites[1];
        }
    }
    #endregion
相關文章
相關標籤/搜索