当前位置: 首页 > wzjs >正文

手机网站建站系统网络营销是什么?

手机网站建站系统,网络营销是什么?,wordpress自定义弹窗,html网页设计作业成品免费实现步骤 在Unity中实现一个功能,当鼠标或触摸超过一定时间没有操作时,自动返回待机界面。 检测输入 首先,我需要检测用户的输入,无论是鼠标还是触摸。Unity的Input系统可以检测到鼠标和触摸事件,比如Input.GetAxis…

实现步骤

在Unity中实现一个功能,当鼠标或触摸超过一定时间没有操作时,自动返回待机界面。

检测输入

首先,我需要检测用户的输入,无论是鼠标还是触摸。Unity的Input系统可以检测到鼠标和触摸事件,比如Input.GetAxis(“Mouse X”)或者Input.touchCount。

  • 鼠标移动:通过 Input.GetAxis 检测光标移动。
  • 鼠标点击:检测左键(0)、右键(1)按下。
  • 触摸事件:识别触摸开始(Began)和移动(Moved),忽略静止(Stationary)。
// 检测鼠标或触摸输入private bool IsInputDetected(){// 鼠标移动检测if (Input.GetAxis("Mouse X") != 0 || Input.GetAxis("Mouse Y") != 0){return true;}// 鼠标点击检测if (Input.GetMouseButtonDown(0) || Input.GetMouseButtonDown(1)){return true;}// 触摸检测if (Input.touchCount > 0){Touch touch = Input.GetTouch(0);if (touch.phase == TouchPhase.Began || touch.phase == TouchPhase.Moved){return true;}}return false;}

计时器

当有输入的时候,我需要重置一个计时器。如果没有输入,计时器就会一直累加,直到超过设定的超时时间,比如30秒,这时候就触发返回待机界面的动作。

  • 设置超时时间:在Inspector面板中调整 timeoutDuration(默认为30秒)。
void Update(){if (IsInputDetected()){currentIdleTime = 0f; // 检测到输入,重置计时}else{currentIdleTime += Time.deltaTime; // 无输入,累计时间if (currentIdleTime >= timeoutDuration){// 超时触发返回待机}}}

返回待机界面

  • 待机界面:根据项目需求选择加载场景或激活UI:
    • 场景切换:确保待机场景(如StandbyScene)在Build Settings中。
    • UI激活:取消注释UI相关代码,并在Inspector中绑定对应的UI对象。
// 返回待机界面private void ReturnToStandby(){// 示例:重新加载待机场景,替换为你的逻辑SceneManager.LoadScene("StandbyScene");// 或激活UI元素// standbyUI.SetActive(true);}

完整代码

using UnityEngine;
using UnityEngine.SceneManagement;public class IdleDetector : MonoBehaviour
{[SerializeField] private float timeoutDuration = 30f; // 超时时间(秒)private float currentIdleTime;void Update(){if (IsInputDetected()){currentIdleTime = 0f; // 检测到输入,重置计时}else{currentIdleTime += Time.deltaTime; // 无输入,累计时间if (currentIdleTime >= timeoutDuration){ReturnToStandby(); // 超时触发返回待机}}}// 检测鼠标或触摸输入private bool IsInputDetected(){// 鼠标移动检测if (Input.GetAxis("Mouse X") != 0 || Input.GetAxis("Mouse Y") != 0){return true;}// 鼠标点击检测if (Input.GetMouseButtonDown(0) || Input.GetMouseButtonDown(1)){return true;}// 触摸检测if (Input.touchCount > 0){Touch touch = Input.GetTouch(0);if (touch.phase == TouchPhase.Began || touch.phase == TouchPhase.Moved){return true;}}return false;}// 返回待机界面private void ReturnToStandby(){// 示例:重新加载待机场景,替换为你的逻辑SceneManager.LoadScene("StandbyScene");// 或激活UI元素// standbyUI.SetActive(true);}
}

优化

  • 在非活动界面暂停检测,减少不必要的计算。
  • 用UnityEvent实现超时触发
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.Events;public class IdleDetector : MonoBehaviour
{[SerializeField] private float timeoutDuration = 30f; // 超时时间(秒)private float currentIdleTime;[SerializeField] private bool isDetector = false;[SerializeField] private UnityEvent onIdleEvent;//启用检测public void SetDetectorState(bool state){isDetector = state;}//重置时间private void ResetTimer(){currentIdleTime = 0f; }void Update(){if(!isDetector)return;if (IsInputDetected()){ResetTimer();// 检测到输入,重置计时}else{currentIdleTime += Time.deltaTime; // 无输入,累计时间if (currentIdleTime >= timeoutDuration){onIdleEvent?.Invoke();ResetTimer();// 如果需要持续检测,可以重置计时器}}}// 检测鼠标或触摸输入private bool IsInputDetected(){// 鼠标移动检测if (Input.GetAxis("Mouse X") != 0 || Input.GetAxis("Mouse Y") != 0){return true;}// 鼠标点击检测if (Input.GetMouseButtonDown(0) || Input.GetMouseButtonDown(1)){return true;}// 触摸检测if (Input.touchCount > 0){Touch touch = Input.GetTouch(0);if (touch.phase == TouchPhase.Began || touch.phase == TouchPhase.Moved){return true;}}return false;}
}

测试

  • 挂载脚本:将脚本挂载到场景中一个持久存在的对象(如空对象 IdleDetector)。
    在这里插入图片描述
http://www.dtcms.com/wzjs/303602.html

相关文章:

  • 微信小网站制作苏州网站建设制作公司
  • 桐乡 网站建设高端企业网站模板
  • 网站图片优化百度seo关键词优化
  • 用户上传商品网站用什么做经典营销案例分析
  • 云建站平台哪家好windows优化大师提供的
  • 网站搭建完手机访问一个新品牌如何推广
  • 招聘网站建设方案模板下载正规接单赚佣金的app
  • php怎么做多个网站网络推广怎么做
  • 梧州建设厅官方网站seo网站推广推荐
  • 阿里云服务器网站建设seo公司上海
  • 网站建设教程详解中国百强企业榜单
  • 政府网站建设内容规划南昌做seo的公司有哪些
  • 电子商务网站建设基本步骤bt种子磁力搜索引擎
  • 怀化市委网站网络营销知识
  • 手机版网站开发框架厦门人才网
  • 建手机网站多少钱惠州企业网站seo
  • 购物网站做推广爱站小工具
  • 青县网站制作百度推广营销页
  • 广州建网站兴田德润很好电商网站排名
  • 织梦网站调节网站手机百度网页版 入口
  • 网站开发设如何宣传网站
  • 电子商务网站建设 市场分析b2b电商平台
  • 在日本做网站百度爱采购优化软件
  • 知名响应式网站企业b2b网站推广排名
  • 贵州省住房和城乡建设厅查询网站seo优化专员
  • 贵阳网站推广有几家优化网络软件
  • 俄罗斯网络攻击数量增长了80%网站seo具体怎么做
  • 北京公司建站模板seo与网络推广的区别和联系
  • 定制鱼缸一般多少钱seo排名点击首页
  • 网站建设的技术需要百度地图优化