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); } } } } }
标签:newTouch,TextMesh,text,void,点击,Unity,-----,Input,public From: https://www.cnblogs.com/clf125800/p/17130950.html