unity實(shí)現(xiàn)文字滾動(dòng)效果
更新時(shí)間:2021年02月23日 16:48:57 作者:被代碼折磨的狗子
這篇文章主要為大家詳細(xì)介紹了unity實(shí)現(xiàn)文字滾動(dòng)效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
本文實(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#實(shí)現(xiàn)Winform序在系統(tǒng)托盤顯示圖標(biāo)和開機(jī)自啟動(dòng)
這篇文章主要為大家詳細(xì)介紹了C#如何實(shí)現(xiàn)Winform序在系統(tǒng)托盤顯示圖標(biāo)和開機(jī)自啟動(dòng)功能,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以了解下2025-01-01
C#使用Pipelines實(shí)現(xiàn)處理Socket數(shù)據(jù)包
這篇文章主要為大家詳細(xì)介紹了C#如何使用Pipelines實(shí)現(xiàn)處理Socket數(shù)據(jù)包,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下2023-12-12
C# WinForms中實(shí)現(xiàn)MD5的加密
MD5(消息摘要算法第5版)是一種廣泛使用的哈希函數(shù),可以生成一個(gè)128位(16字節(jié))的哈希值,通常用于數(shù)據(jù)完整性校驗(yàn)和密碼存儲(chǔ),在Windows Forms應(yīng)用程序中實(shí)現(xiàn)MD5加密,可以用于用戶密碼的安全存儲(chǔ)和數(shù)據(jù)的完整性驗(yàn)證,本文將詳細(xì)介紹了如何在WinForms中實(shí)現(xiàn)MD5加密2024-10-10
詳解WPF如何動(dòng)態(tài)生成DataGrid的行和列
在日常開發(fā)中,DataGrid作為二維表格,非常適合數(shù)據(jù)的展示和統(tǒng)計(jì),本文以一些簡(jiǎn)單的小例子,簡(jiǎn)述在WPF開發(fā)中,如何動(dòng)態(tài)生成DataGrid的行和列,需要的可以了解下2024-02-02
C#中自定義高精度Timer定時(shí)器的實(shí)例教程
這篇文章主要介紹了C#中自定義高精度Timer定時(shí)器的實(shí)例教程,多線程的Timer編寫需要注意線程安全的問題,需要的朋友可以參考下2016-04-04

