【问题标题】:operation is not valid due to current state of object in Unity 3d由于 Unity 3d 中对象的当前状态,操作无效
【发布时间】:2014-11-08 14:46:08
【问题描述】:

我不熟悉统一和在相机上练习变换动作。我在上面应用的 c# 脚本的代码是。

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


public class HelloWorld : MonoBehaviour {


    public float speed = 2f;
    // Use this for initialization
    void Start () {

    }

    // Update is called once per frame 
    void Update () {
        transform.Translate(new Vector3(speed,0,transform.position.z) * Time.deltaTime);

    }
}

但控制台显示错误说明:

我搜索了问题并设法得到调试器无法从堆栈顶部获取任何东西。但我无法弄清楚它与特定代码的关系以及实际问题存在于哪里?

错误日志: solution->Open(bstrSolution)m_CurrentEntriesPtr == NULL || !m_IsGettingEntries UnityEditorInternal.LogEntries:GetEntryInternal(Int32, LogEntry) UnityEditor.ConsoleWindow:OnGUI() (在 C:\BuildAgent\work\d63dfc6385190b60\Editor\Mono\ConsoleWindow.cs:454) System.Reflection.MonoMethod:InternalInvoke(Object, Object[], Exception&) System.Reflection.MonoMethod:Invoke(Object, BindingFlags, Binder, Object[], CultureInfo) (在 /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Reflection/MonoMethod .cs:222) System.Reflection.MethodBase:Invoke(Object, Object[]) (在 /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Reflection/MethodBase.cs:115) UnityEditor.HostView:Invoke(String, Object) (在 C:\BuildAgent\work\d63dfc6385190b60\Editor\Mono\GUI\DockArea.cs:241) UnityEditor.HostView:Invoke(String) (在 C:\BuildAgent\work\d63dfc6385190b60\Editor\Mono\GUI\DockArea.cs:234) UnityEditor.DockArea:OnGUI() (在 C:\BuildAgent\work\d63dfc6385190b60\Editor\Mono\GUI\DockArea.cs:671) [C:\BuildAgent\work\d63dfc6385190b60\Editor/Src/EditorMonoConsole.h 第 90 行] (文件名:C:/BuildAgent/work/d63dfc6385190b60/Editor/Mono/ConsoleWindow.cs 行:454) m_CurrentEntriesPtr == NULL || !m_IsGettingEntries UnityEditorInternal.LogEntries:GetEntryInternal(Int32, LogEntry) UnityEditor.ConsoleWindow:OnGUI() (在 C:\BuildAgent\work\d63dfc6385190b60\Editor\Mono\ConsoleWindow.cs:458) System.Reflection.MonoMethod:InternalInvoke(Object, Object[], Exception&) System.Reflection.MonoMethod:Invoke(Object, BindingFlags, Binder, Object[], CultureInfo) (在 /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Reflection/MonoMethod .cs:222) System.Reflection.MethodBase:Invoke(Object, Object[]) (在 /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Reflection/MethodBase.cs:115) UnityEditor.HostView:Invoke(String, Object) (在 C:\BuildAgent\work\d63dfc6385190b60\Editor\Mono\GUI\DockArea.cs:241) UnityEditor.HostView:Invoke(String) (在 C:\BuildAgent\work\d63dfc6385190b60\Editor\Mono\GUI\DockArea.cs:234) UnityEditor.DockArea:OnGUI() (在 C:\BuildAgent\work\d63dfc6385190b60\Editor\Mono\GUI\DockArea.cs:671) [C:\BuildAgent\work\d63dfc6385190b60\Editor/Src/EditorMonoConsole.h 第 90 行] (文件名:C:/BuildAgent/work/d63dfc6385190b60/Editor/Mono/ConsoleWindow.cs 行:458) InvalidOperationException:由于对象的当前状态,操作无效 在 System.Collections.Stack.Peek () [0x0000c] 在 /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Collections/Stack.cs:321 在 UnityEngine.GUILayoutUtility.EndLayoutGroup () [0x0001b] 在 C:\BuildAgent\work\d63dfc6385190b60\artifacts\EditorGenerated\GUILayoutUtility.cs:223 在 UnityEditor.SplitterGUILayout.EndVerticalSplit () [0x00000] 在 C:\BuildAgent\work\d63dfc6385190b60\Editor\Mono\GUI\Splitter.cs:491 在 UnityEditor.ConsoleWindow.OnGUI () [0x00761] 在 C:\BuildAgent\work\d63dfc6385190b60\Editor\Mono\ConsoleWindow.cs:488 在(包装器托管到本机) System.Reflection.MonoMethod:InternalInvoke (object,object[],System.Exception&) 在 System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] 参数, System.Globalization.CultureInfo 文化) [0x000d0] 在 /Users/builduser/buildslave/mono -runtime-and-classlibs/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:222

【问题讨论】:

  • 1) 您可以选择、复制和粘贴日志信息为文本。屏幕截图很难阅读。 2)您是否双击突出显示的行?它应该打开 Mono 并显示问题所在的行。发布该行加上周围的行以获取上下文。

标签: debugging unity3d


【解决方案1】:
transform.Translate(Vector3.right * speed * Time.deltaTime);

【讨论】:

  • 如果你解释你想做什么,我会告诉你,例如 transform.Translate(Vector3.forward * Time.deltaTime);
  • 谢谢兄弟,我想沿 x 轴移动相机。我也放置了一个立方体,但是通过应用 Vector3.forward 它保持静止并在几秒钟后离开场景。
  • transform.Translate(Vector3.right * Time.deltaTime);
  • 你可能想要Vector3.right * speed * Time.deltaTime。 @user 与 Vector3 的乘法也会创建新的对象! (本例中的结构)
猜你喜欢
  • 2010-10-18
  • 1970-01-01
  • 2020-04-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多