制作待机设定 图片视频都可以

本文介绍了一个使用Unity实现的游戏时间控制脚本。该脚本通过检测玩家操作的时间间隔来判断是否进入待机状态,并提供了取消待机的功能。脚本利用了MonoBehaviour特性,通过Update方法实时监测输入并调整游戏状态。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class timeControl : MonoBehaviour
{
public Button game;
///
/// 检测时间间隔
///
[Header(“检测时间间隔”)]
public float maxTimeOffset;
///
/// 编辑器是否开启检测
///
[Header(“编辑器是否开启检测”)]
public bool IsEditorOpen = false;
///
/// 上次的时间
///
private float lasterTime;
// Start is called before the first frame update
void Start()
{
game.onClick.AddListener(SC_Onclick);
}

// Update is called once per frame
void Update()
{
    float nowTime = Time.time;
    if (Input.GetMouseButtonDown(0))
    {
        IsEditorOpen = true;
        lasterTime = nowTime;//更新触摸时间
    }
    float offsetTime = Mathf.Abs(nowTime - lasterTime);
    //Debug.Log("长时间无操作 offsetTime:" + offsetTime);
    if (offsetTime > maxTimeOffset)
    {
        UIManger.instance.Standby_Video();
        game.gameObject.SetActive(true);
        IsEditorOpen = false;
        offsetTime = 0;
    }
    else
    {
        Debug.Log("长时间无操作 offsetTime:" + offsetTime);
    }
 
}

public void SC_Onclick()
{
if (LoadXml.instance.data_dict.ContainsKey(30))
{
Layer1.instance.SendMessage(UIManger.instance.layerIndex, LoadXml.instance.data_dict[30][0].code);
}

    Debug.Log("取消待机视频播放");
}

}

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值