• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

unity实现文字滚动效果

c# 搞代码 4年前 (2022-01-09) 50次浏览 已收录 0个评论

本文实例为大家分享了unity实现文字滚动效果的具体代码,供大家参考,具体内容如下

效果:

代码:

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("正方向")]
 JustDire<strong>本文来源gaodai#ma#com搞@代~码^网+</strong>ction,
 [EnumAttirbute("反方向")]
 OppositeDirection
}

public class ScrollInformation : MonoBehaviour {
 [EnumAttirbute("类型")]
 public MoveType moveType; //类型
 [EnumAttirbute("方向")]
 public Direction direction; //方向

 public float Speed; //速度
 public float OverPos; //结束位置
 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;
    }
   }
  }
 }
}

枚举类型中文显示在上一篇

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持搞代码


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:unity实现文字滚动效果
喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址