激活和停用调用功能 [英] Activate and Deactivate Invoke function

查看:67
本文介绍了激活和停用调用功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用C#语言来延迟我在Unity中的功能.通过使用Invoke,我实现了将光标移动到特定区域时增加延迟.但是,现在当光标从该特定区域移动时,我需要取消Invoke.这个想法是,当我不小心将光标移到该区域时,我可以取消在该区域调用的任何函数. 这是我当前的代码.

I attempted to give a delay to my function in Unity using C# language. By using Invoke, I achieved to add delay when the cursor is moved to a certain area. However, now I need to cancel the Invoke when the cursor is moved from that certain area. The idea is, when I accidentally move the cursor to the area, I can cancel whatever function being invoked there. Here's my current code.

void SceneCall(){
    Application.LoadLevel (MainMenu);
}

void SceneCallIn(){
    Invoke ("SceneCall", 3f);
}
if (_newGameButton.Contains (Event.current.mousePosition)) {
        SceneCallIn();
    }

我尝试不使用CancelInvoke(),之后将光标移到_newGameButton时,它甚至都不想再调用.如何取消调用然后再次激活它?谢谢您的回答〜

I tried to use CancelInvoke() as else, and it even doesn't want to invoke anymore when I move my cursor to _newGameButton afterwards. How do you cancel an Invoke then activate it once again? Thank you for your answer~

就像@Programmer在评论中说的那样,我真正想做的是当鼠标定位在特定点时,计时器将开始计数. 3秒后 MainMenu场景将被加载.当计时器正在计数并且指针从该特定位置移开时,我希望计时器停止并且不希望再加载MainMenu场景.

Like @Programmer says in comments, what I exactly want to do is when my mouse is position at a certain point, timer will start counting. After 3 seconds MainMenu scene will be loaded. While the timer is counting and the pointer is moved away from that certain position, I want the timer to stop and I don't want the MainMenu scene to be loaded anymore.

推荐答案

如果您确实想拥有翻转"等功能,那么这里是完整的教程:

If you truly want to have "rollovers" and so on, here is a full tutorial:

https://stackoverflow.com/a/36046495/294884

真的,在您完成所有工作之前,您将必须变得完全精通.

Really you will have to become totally expert in all that, before you can do it.

但是我必须再次告诉你

15年来,无论出于任何原因,您都不应在界面中使用过渡功能.

For 15 years now, you should never use rollovers for any reason in interface.

这篇关于激活和停用调用功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆