using System.Collections;
using System.Collections.Generic;
using UnityEngine.UI;
using UnityEngine;
using System;
using Sirenix.OdinInspector;
using UnityEngine.EventSystems;
public class ScrollInformation : MonoBehaviour,IPointerEnterHandler,IPointerExitHandler
{
[LabelText("速度")]
public float Speed;
[LabelText("要滚动的目标")]
public RectTransform Information;
//移动物体与父物体宽度差值
float tmpWidth = 0;
///
/// 开启移动
///
bool openMove;
void Start()
{
RectTransform tmpParentRectTransform = transform.GetComponent();
tmpWidth = Information.rect.width - tmpParentRectTransform.rect.width;
}
void FixedUpdate()
{
ScrollResult();
}
void ScrollResult()
{
if (!openMove) return;
if (tmpWidth > 0)
{
float tmpX = Information.anchoredPosition.x - Time.fixedDeltaTime * Speed;
Information.SetLocalPositionX(tmpX);
if (Information.anchoredPosition.x < -tmpWidth)
{
Information.SetLocalPositionX(0);
}
}
}
public void OnPointerEnter(PointerEventData eventData)
{
openMove = true;
}
public void OnPointerExit(PointerEventData eventData)
{
openMove = false;
Information.SetLocalPositionX(0);
}
}