unity實(shí)現(xiàn)文字滾動(dòng)效果
本文實(shí)例為大家分享了unity實(shí)現(xiàn)文字滾動(dòng)效果的具體代碼,供大家參考,具體內(nèi)容如下
效果:
代碼:
using System.Collections; using System.Collections.Generic; using UnityEngine.UI; using UnityEngine; using System; //移動(dòng)類型 [Serializable] public enum MoveType { [EnumAttirbute("水平滾動(dòng)")] horMove, [EnumAttirbute("垂直滾動(dòng)")] 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; //滾動(dòng)信息 void Start () { } void FixedUpdate() { ScrollResult(); } //滾動(dòng)效果 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; } } } } }
枚舉類型中文顯示在上一篇
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
C#使用udp如何實(shí)現(xiàn)消息的接收和發(fā)送
這篇文章主要介紹了C#使用udp如何實(shí)現(xiàn)消息的接收和發(fā)送問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-02-02C#創(chuàng)建SQLite控制臺(tái)應(yīng)用程序詳解
這篇文章主要為大家詳細(xì)介紹了C#創(chuàng)建SQLite控制臺(tái)應(yīng)用程序,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-07-07C#中DataTable實(shí)現(xiàn)行列轉(zhuǎn)換的方法
這篇文章主要介紹了C#中DataTable實(shí)現(xiàn)行列轉(zhuǎn)換的方法,實(shí)例分析了C#操作DataTable的相關(guān)技巧,非常具有實(shí)用價(jià)值,需要的朋友可以參考下2015-04-04支持windows與linux的php計(jì)劃任務(wù)的實(shí)現(xiàn)方法
這篇文章主要介紹了支持windows與linux的php計(jì)劃任務(wù)的實(shí)現(xiàn)方法,較為詳細(xì)的講述了php計(jì)劃任務(wù)中涉及到的php程序?qū)崿F(xiàn)方法、Windows計(jì)劃任務(wù)實(shí)現(xiàn)方法等,需要的朋友可以參考下2014-11-11C#5.0中的異步編程關(guān)鍵字async和await
這篇文章介紹了C#5.0中的異步編程關(guān)鍵字async和await,文中通過示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-06-06C#實(shí)現(xiàn)學(xué)生成績(jī)管理系統(tǒng)
這篇文章主要為大家詳細(xì)介紹了C#實(shí)現(xiàn)學(xué)生成績(jī)管理系統(tǒng),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-08-08C#使用log4net結(jié)合sqlite數(shù)據(jù)庫實(shí)現(xiàn)記錄日志
因?yàn)榻Y(jié)構(gòu)化的數(shù)據(jù)庫存儲(chǔ)的日志信息,可以寫專門的軟件讀取歷史日志信息,通過各種條件篩選,可操作性極大增強(qiáng),有這方面需求的開發(fā)人員可以考慮,本文給大家介紹了C#使用log4net結(jié)合sqlite數(shù)據(jù)庫記錄日志,需要的朋友可以參考下2024-10-10