unity實現(xiàn)文字滾動效果
更新時間:2021年02月23日 16:48:57 作者:被代碼折磨的狗子
這篇文章主要為大家詳細介紹了unity實現(xiàn)文字滾動效果,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
本文實例為大家分享了unity實現(xiàn)文字滾動效果的具體代碼,供大家參考,具體內(nèi)容如下
效果:


代碼:
using System.Collections;
using System.Collections.Generic;
using UnityEngine.UI;
using UnityEngine;
using System;
//移動類型
[Serializable]
public enum MoveType
{
[EnumAttirbute("水平滾動")]
horMove,
[EnumAttirbute("垂直滾動")]
verMove
}
//方向
[Serializable]
public enum Direction
{
[EnumAttirbute("正方向")]
JustDirection,
[EnumAttirbute("反方向")]
OppositeDirection
}
public class ScrollInformation : MonoBehaviour {
[EnumAttirbute("類型")]
public MoveType moveType; //類型
[EnumAttirbute("方向")]
public Direction direction; //方向
public float Speed; //速度
public float OverPos; //結(jié)束位置
public float StartPos; //開始位置
public RectTransform Information; //滾動信息
void Start () {
}
void FixedUpdate()
{
ScrollResult();
}
//滾動效果
Vector2 pos;
void ScrollResult()
{
//判斷方向
if (moveType == MoveType.horMove)
{
Debug.Log("水平&正方向");
pos = new Vector2(Speed * Time.fixedDeltaTime, 0);
if (direction== Direction.JustDirection)
{
if (Information.anchoredPosition.x < OverPos)
{
Information.anchoredPosition = new Vector2(StartPos, Information.anchoredPosition.y);
}
else
{
Information.anchoredPosition += -pos;
}
}
else
{
Debug.Log("水平&反方向");
if (Information.anchoredPosition.x > StartPos)
{
Information.anchoredPosition = new Vector2(OverPos, Information.anchoredPosition.y);
}
else
{
Information.anchoredPosition += pos;
}
}
}
else
{
Debug.Log("垂直&正方向");
pos = new Vector2(0,Speed * Time.fixedDeltaTime);
if (direction == Direction.OppositeDirection)
{
if (Information.anchoredPosition.y < OverPos)
{
Information.anchoredPosition = new Vector2(Information.anchoredPosition.x, StartPos);
}
else
{
Information.anchoredPosition += -pos;
}
}
else
{
if (Information.anchoredPosition.y > StartPos)
{
Information.anchoredPosition = new Vector2(Information.anchoredPosition.x, OverPos);
}
else
{
Information.anchoredPosition += pos;
}
}
}
}
}
枚舉類型中文顯示在上一篇
以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
C#實現(xiàn)Winform序在系統(tǒng)托盤顯示圖標和開機自啟動
這篇文章主要為大家詳細介紹了C#如何實現(xiàn)Winform序在系統(tǒng)托盤顯示圖標和開機自啟動功能,文中的示例代碼講解詳細,感興趣的小伙伴可以了解下2025-01-01
C#使用Pipelines實現(xiàn)處理Socket數(shù)據(jù)包
這篇文章主要為大家詳細介紹了C#如何使用Pipelines實現(xiàn)處理Socket數(shù)據(jù)包,文中的示例代碼講解詳細,感興趣的小伙伴可以跟隨小編一起學習一下2023-12-12

