简体   繁体   English

为什么我在 Unity 编辑器 window 中的输入工作正常,但在游戏构建中却完全没有?

[英]Why is my input in the Unity editor window working perfectly but not at all in the game build?

I have a pretty simple script:我有一个非常简单的脚本:

 void Start()
 {
 }
 void Update()
 {
     if (Input.GetKeyDown("return")){
         play();
     }
 }
 void play()
 {
     anim.SetTrigger("playbutton");
 }

It works wonders in the editor window, but when I build and run, absolutely nothing happens.它在编辑器 window 中创造了奇迹,但是当我构建和运行时,绝对没有任何反应。 It loads the scene just fine, but the button inputs don't seem to be getting through.它可以很好地加载场景,但按钮输入似乎没有通过。

UPDATE: I tried several different buttons, but those didn't work.更新:我尝试了几个不同的按钮,但这些都不起作用。 I did try putting the anim.SetTrigger line in the Start function, and it didn't work either, which means that this is a problem with the animator/script, not the input.我确实尝试将 anim.SetTrigger 行放在 Start function 中,但它也不起作用,这意味着这是动画师/脚本的问题,而不是输入的问题。

the script seems simple and fine, i suggest that u try the same script in an empty project to see if it works or not if it dose work try to apply the script on an other game object and run.该脚本看起来简单而精细,我建议您在一个空项目中尝试相同的脚本,看看它是否有效,如果它有效,请尝试将该脚本应用于其他游戏 object 并运行。 lets say it didn't work u can try this instead "if (Input.GetKeyDown(KeyCode.Return)" or try to use an other key假设它不起作用,您可以尝试使用“if (Input.GetKeyDown(KeyCode.Return)”或尝试使用其他键

I'VE FOUND IT.我找到了。 The animation component in the object in question was set to cull completely, not always animate.有问题的 object 中的 animation 组件被设置为完全剔除,并不总是动画。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Admob 在 android 版本中不起作用。 在统一编辑器中完美运行 - Admob not working in android build. Works perfectly in unity editor UI hover 效果在 Unity Editor 中有效但在游戏构建中无效 - UI hover effect working in Unity Editor but not in game build Unity-将编辑器窗口停靠在游戏视图上方 - Unity - Dock an editor window above the game view 脚本在 Unity 运行时在编辑器中工作,而不是在构建中 - Scripts working during Unity Runtime in Editor, Not in Build json加载无法在构建中使用,但可以在统一编辑器中使用 - json load not working in build but works in unity editor Unity 脚本在编辑器中运行良好,但在构建中运行不佳 - Unity Scripts Working Fine in Editor, But not in Build Unity:视频在编辑器中工作,但在构建后不在 Android 上工作 - Unity: Video is working in editor but not on Android after build 构建后 Unity 游戏无法运行 (MissingMethodException) - Unity game not working after build (MissingMethodException) 为 Windows 构建游戏时,Unity PlayerPrefs 不起作用 - Unity PlayerPrefs are not working when the game is build for Windows 为什么当在构建环境中运行游戏时,单击“开始游戏”按钮时,它不起作用,而在编辑器中却起作用? - Why when clicking on START GAME button when the game is running in build it's not working does nothing but it's working in the editor?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM