powerfun-unity/Assets/HomeMessageController.cs

53 lines
1.5 KiB
C#
Raw Normal View History

2021-12-30 16:51:04 +08:00
using DG.Tweening;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class HomeMessageController : MonoBehaviour
{
// Start is called before the first frame update
float startX;
private void Awake()
{
startX = transform.Find("TextContainer/Content").localPosition.x;
}
void Start()
{
}
float timer = 2;
public float? textWidth = null;
private bool isAnimated = false;
public void Initial()
{
transform.Find("TextContainer/Content").localPosition = new Vector2(startX, transform.Find("TextContainer/Content").localPosition.y);
isAnimated = false;
}
float playtime = 0;
2021-12-30 16:51:04 +08:00
// Update is called once per frame
void Update()
{
timer -= Time.deltaTime;
if (timer <= 0)
{
//do
if (textWidth.HasValue && textWidth > 180 && !isAnimated)
{
isAnimated = true;
var offset = textWidth.Value - 180;
var game = transform.Find("TextContainer/Content");
var v = 20 / 0.3f;
playtime = offset / v;
//匀速播放
game.DOLocalMoveX(startX - offset, playtime).onComplete
2021-12-30 16:51:04 +08:00
= () => Invoke("returnAni", 1.5f);
}
timer += 3;
2021-12-30 16:51:04 +08:00
}
}
void returnAni()
{
transform.Find("TextContainer/Content").DOLocalMoveX(startX, playtime);
2021-12-30 16:51:04 +08:00
}
}