本文实例为大家分享了unity实现文字滚动效果的具体代码,供大家参考,具体内容如下
效果:
代码:
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111using 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; //结束位置 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; } } } } }
枚举类型中文显示在上一篇
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持靠谱客。
最后
以上就是危机黑夜最近收集整理的关于unity实现文字滚动效果的全部内容,更多相关unity实现文字滚动效果内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复