美文网首页
UI随机出现金币dotween

UI随机出现金币dotween

作者: 沉麟 | 来源:发表于2019-04-03 17:38 被阅读0次
            ```
        int rans = UnityEngine.Random.Range(0, 5);
        if (rans == 0) return;
    
        for (int i = 0; i < rans; i++)
        {
            GameObject go = Instantiate(coinObj, coinObj.transform.parent);
            
    
            go.transform.localPosition = Utils.WorldToUGUIPosition(enemyPos);
            go.SetActive(true);
            int vx = UnityEngine.Random.Range(0, 2);
            int vy = UnityEngine.Random.Range(0, 2);
            List<int> vxy = new List<int>() { -1, 1 };
            Vector3[] path = new Vector3[3];
            path[0] = go.transform.position;
            path[1] = go.transform.position - new Vector3(vxy[vx], vxy[vy], 0);
            path[2] = coinTarget.transform.position;
    
            Sequence sequence = DOTween.Sequence();
            sequence.Append(go.transform.DOScale(390.0f, 0.5f));
            sequence.Append(go.transform.DOScale(300.0f, 0.5f));
    
            go.transform.DORotate(new Vector3(0, 180, 0), 0.5f).SetLoops(-1);
            var tweenPath = go.transform.DOPath(path, 1f, PathType.CatmullRom);
            tweenPath.onComplete = () =>
            {
                if (!isScaleCoin)
                {
                    isScaleCoin = true;
                    Sequence coinSeq = DOTween.Sequence();
                    coinSeq.Append(coinTarget.transform.DOScale(1.5f, 0.1f));
                    coinSeq.Append(coinTarget.transform.DOScale(1f, 0.1f));
                    coinSeq.AppendCallback(() =>
                    {
                        isScaleCoin = false;
                    });
    
                }
    
                Destroy(go);
                SoundManager.Instance.Play(Enums.SoundId.SoundCoin);
                DynamicData.Instance.coin++;
                OnRefresh();
            };
            tweenPath.SetEase(Ease.InOutSine);
        }
    
    世界坐标转换
    ```public static Vector3 WorldToUGUIPosition(Vector3 pos) {
            Vector3 viewPos = Camera.main.WorldToViewportPoint(pos);
            return new Vector3((viewPos.x-0.5f)*UIMgr.Instance.width, (viewPos.y-0.5f)*UIMgr.Instance.height, 0);
        }
    

    相关文章

      网友评论

          本文标题:UI随机出现金币dotween

          本文链接:https://www.haomeiwen.com/subject/cuozbqtx.html