1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class TickerItem : MonoBehaviour
{
float tickerWidth;
float pixelsPerSecond;
RectTransform rt;

public float GetXPosition { get { return rt.anchoredPosition.x; } }
public float GetWidth { get { return rt.rect.width; } }
public void Initialize(float tickerWidth,float pixelsPerSecond, string message)
{
this.tickerWidth = tickerWidth;
this.pixelsPerSecond = pixelsPerSecond;
rt = GetComponent<RectTransform>();
GetComponent<Text>().text = message;
}
void Update()
{
rt.position += pixelsPerSecond * Time.deltaTime * Vector3.left;
if(GetXPosition <= 0 - tickerWidth - GetWidth){
Destroy(gameObject);
Debug.Log("Destroy");
}
}
}