powerfun-unity/Assets/HomeMessageController.cs

44 lines
1.1 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;
[HideInInspector]public bool isAnimated = false;
// 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");
game.DOLocalMoveX(startX - offset, 0.5f).onComplete
= () => Invoke("returnAni", 1.5f);
}
timer += 4;
}
}
void returnAni()
{
transform.Find("TextContainer/Content").DOLocalMoveX(startX, 0.5f);
}
}