【Unity】【UI.Text】【Code】通用代码库(五)——文字循环滚动+touch控制上下滚动
来源:互联网 发布:php 敏感词过滤 编辑:程序博客网 时间:2024/04/30 05:50
通用代码库
基于Unity5.6.0f
using System.Collections;using System.Collections.Generic;using UnityEngine;using UnityEngine.UI;public class TextRoll : MonoBehaviour{ public Transform txt; public float Speed = 20;//滚动速度 public double num;//Screen.height的系数, private Vector3 txtpos; // Use this for initialization void Start () { txt.localPosition = new Vector3(txt.localPosition.x, -Screen.height* 0.25f, txt.localPosition.z); txtpos = txt.localPosition; Debug.Log("txtpos: " + txtpos); } // Update is called once per frame void Update () { //手指控制text上下滚动 if (1 == Input.touchCount) { var touch = Input.GetTouch(0); if (touch.position.y > Screen.height * 0.0f && touch.position.y < Screen.height * 0.25f)//限制touch范围 { if (txt.localPosition.y <= num * Screen.height || txt.localPosition.y >= txtpos.y)//限制text高度 { Vector2 deltaPos = touch.deltaPosition; transform.Translate(new Vector3(0, 10*deltaPos.y * Time.deltaTime, 0), Space.World); } } } //文字自动上下循环滚动 if (Input.touchCount == 0) { if (txt.localPosition.y <= num * Screen.height) { float y = txt.localPosition.y + Speed * Time.deltaTime; txt.localPosition = new Vector3(0, y, 0); //Debug.Log(txt.position.y); } else { txt.localPosition = txtpos; } } }}
阅读全文
0 0
- 【Unity】【UI.Text】【Code】通用代码库(五)——文字循环滚动+touch控制上下滚动
- HTML文字上下循环滚动代码
- 上下循环滚动代码
- 上下滚动的文字——JS代码
- css控制的上下滚动的文字代码
- jquery上下循环滚动插件 控制li上下循环滚动
- 【Unity】【Code】【UI】通用代码库(二)——UI跟随GameProject移动
- 上下循环滚动代码JAVASCRIPT
- 文字上下滚动并来回循环
- jquery实现文字上下循环滚动效果
- 文字无缝滚动jQuery上下滚动js效果代码
- 文字上下滚动
- 使文字上下滚动
- 文字上下滚动
- 文字上下滚动特效
- 上下滚动的文字
- 文字上下无缝滚动
- 文字上下滚动
- UISplitViewController翻译
- 【Linux应用开发】malloc内存分配原理
- 【机器学习实战】制作五子棋AI之一:图片预处理(尺寸变换和增加alpha通道)
- ubuntu服务器安装配置apache2
- 浅谈Java中CountDownLatch的用法
- 【Unity】【UI.Text】【Code】通用代码库(五)——文字循环滚动+touch控制上下滚动
- 非阻塞式socket的select()用法
- mysql操作查询结果case when then else end用法举例
- post提交json数据后,java接收json
- 北大oj-1008 C语言
- 聚簇索引与非聚簇索引的区别
- 数学建模_使用excel对字符串进行截取并简单计数
- 分页
- 【汇总】8月下半月上海热门IT互联网科技大会合集