示例#1
0
        private IEnumerator AnimateInfoText(Transform sender, float time, string text, Color color)
        {
            InfoText info = Singleton.Instanse.GetInfoText(sender.position, WorldCanvas.transform);

            info.Set(text, color);

            RectTransform infoTransform = info.transform as RectTransform;
            float         halfWidth     = infoTransform.rect.width / 2f;

            if (infoTransform.position.x > Singleton.Instanse.screen.x / 2f - halfWidth)
            {
                infoTransform.position = new Vector3(Singleton.Instanse.screen.x / 2f - halfWidth, infoTransform.position.y);
            }
            else if (infoTransform.position.x < -Singleton.Instanse.screen.x / 2f + halfWidth)
            {
                infoTransform.position = new Vector3(-Singleton.Instanse.screen.x / 2f + halfWidth, infoTransform.position.y);
            }

            float startTime = 0;

            Vector3 endPos   = new Vector3(info.transform.position.x, 0);
            Color   endColor = color;

            endColor.a = 0;

            while (startTime < time)
            {
                info.transform.position = Vector3.MoveTowards(info.transform.position, endPos, Time.deltaTime);

                info.text.color = Color.Lerp(color, endColor, startTime / time);

                yield return(null);

                startTime += Time.deltaTime;
            }
            ObjectPool.ReturnToPool(info);
        }