Unity TextMesh 操作-----点击显示/影藏+长按方大+旋转
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 111 | using System.Collections; using System.Collections.Generic; using UnityEngine; public class SetActiveLogic : MonoBehaviour { //获取操作对象 public GameObject text; //文字对象 private TextMesh textMesh; //点击时间长 public float touchTime; //初始旋转角度 public float xspeed = 120; //默认不是重新触摸 public bool newTouch = false ; void Start() { this .textMesh = this .GetComponentInParent<TextMesh>(); } // Update is called once per frame void Update() { //MySetActive(); MyFonteSize(); MyRotate(); } //手指点击关闭显示 void MySetActive() { //点击 if (Input.GetMouseButton(0)) { //一个手指点击 if (Input.touchCount == 1 && Input.GetTouch(0).phase == TouchPhase.Began) { text.SetActive( false ); //2个点击 if (Input.GetTouch(0).tapCount == 2) { text.SetActive( true ); //显示 } } } } //长安执行文字放大 void MyFonteSize() { //点击 if (Input.GetMouseButton(0)) { //判断单击 if (Input.touchCount == 1) { Touch touch = Input.GetTouch(0); //判断点击按下 if (touch.phase == TouchPhase.Began) { //修改状态为点击中 newTouch = true ; //开始计时 touchTime = Time.time; } //判断长按 else if (touch.phase == TouchPhase.Stationary) { //判断时长 if (newTouch == true && Time.time - touchTime>1f) { newTouch = false ; //字体大小不能大于20 if (textMesh.fontSize<20) { //设置字体放大 textMesh.fontSize += 1; } } } else { newTouch = false ; } } } } //旋转 void MyRotate() { //按下 if (Input.GetMouseButton(0)) { //单击 if (Input.touchCount ==1) { //滑动 if (Input.GetTouch(0).phase == TouchPhase.Moved) { //旋转(以Y轴) this .textMesh.transform.Rotate(Vector3.up * Input.GetAxis( "Mouse X" ) * xspeed * Time.deltaTime,Space.Self); } } } } } |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 提示词工程——AI应用必不可少的技术
· 地球OL攻略 —— 某应届生求职总结
· 字符编码:从基础到乱码解决
· SpringCloud带你走进微服务的世界