rabidus-test/Assets/CurvedUI/Demo Scenes/Demo Scenes Content/CUI_MoveHeartbeat.cs

32 lines
696 B
C#
Raw Permalink Normal View History

2023-08-15 17:38:54 +03:00
using UnityEngine;
using System.Collections;
public class CUI_MoveHeartbeat : MonoBehaviour {
public float speed;
public bool wrapAroundParent = true;
RectTransform rectie;
RectTransform parentRectie;
void Start(){
rectie = (transform as RectTransform);
parentRectie = transform.parent as RectTransform;
}
// Update is called once per frame
void Update () {
rectie.anchoredPosition = new Vector2(rectie.anchoredPosition.x - speed * Time.deltaTime,
rectie.anchoredPosition.y);
if(wrapAroundParent){
if(rectie.anchoredPosition.x + rectie.rect.width < 0 )
rectie.anchoredPosition = new Vector2(parentRectie.rect.width, rectie.anchoredPosition.y);
}
}
}