彼此欣喜 2022-05-06 22:59 采纳率: 100%
浏览 447
已结题

unity如何长按鼠标左键,实现数字动态增加,每次增加0.1;松开鼠标左键,数字停止变化呢

IEnumerator UVZero() {
float x = float.Parse(objs2[0].GetComponent<text>().text);
x += Time.deltaTime;
objs2[0].GetComponent<text>().text = float.Parse(x.ToString("0.0")).ToString();
yield return null;
}
用了协程 但是数字每次增加不是0.1f</text></text>

  • 写回答

4条回答 默认 最新

  • CoderZ1010 Unity领域优质创作者 2022-05-07 10:33
    关注
    using UnityEngine;
    
    public class Example : MonoBehaviour
    {
        float x = 0f;
    
        private void Update()
        {
            //鼠标按住
            if (Input.GetMouseButton(0))
            {
                x += .1f;
            }
        }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

问题事件

  • 系统已结题 5月15日
  • 已采纳回答 5月7日
  • 创建了问题 5月6日