gpt4 book ai didi

c# - 无法在 C# 中使用命名空间

转载 作者:行者123 更新时间:2023-12-04 16:55:48 27 4
gpt4 key购买 nike

我正在尝试在 Unity 编辑器中开发游戏。
我无法将命名空间从一个脚本使用到另一个脚本。
请在下面找到脚本。

using System;
using UnityEngine;
using UnityStandardAssets.CrossPlatformInput;
namespace UnityStandardAssets.CrossPlatformInput
{
public static class CrossPlatformInputManager
{
public enum ActiveInputMethod
{
Hardware,
Touch
}


private static VirtualInput activeInput;

private static VirtualInput s_TouchInput;
private static VirtualInput s_HardwareInput;
}
}

AxisTouchButton.cs
using System;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityStandardAssets.CrossPlatformInput;

namespace UnityStandardAssets.CrossPlatformInput
{
public class AxisTouchButton : MonoBehaviour, IPointerDownHandler, IPointerUpHandler
{
// designed to work in a pair with another axis touch button
// (typically with one having -1 and one having 1 axisValues)
public string axisName = "Horizontal"; // The name of the axis
public float axisValue = 1; // The axis that the value has
public float responseSpeed = 3; // The speed at which the axis touch button responds
public float returnToCentreSpeed = 3; // The speed at which the button will return to its centre

AxisTouchButton m_PairedWith; // Which button this one is paired with
CrossPlatformInputManager.VirtualAxis m_Axis; // A reference to the virtual axis as it is in the cross platform input

void OnEnable()
{
if (!CrossPlatformInputManager.AxisExists(axisName))
{
// if the axis doesnt exist create a new one in cross platform input
m_Axis = new CrossPlatformInputManager.VirtualAxis(axisName);
CrossPlatformInputManager.RegisterVirtualAxis(m_Axis);
}
else
{
m_Axis = CrossPlatformInputManager.VirtualAxisReference(axisName);
}
FindPairedButton();
}
}
}

脚本 CrossPlatformInputManager有命名空间 UnityStandardAssets.CrossPlatformInput ,但我无法在 AxisTouchButton.cs 中获得该命名空间在 Unity Monodevelop 编辑器中。

附言: 这两个文件位于不同的目录中。

有人能告诉我命名空间有什么问题吗?

谢谢,
罗希特

最佳答案

当您的类已经在命名空间 UnityStandardAssets.CrossPlatformInput 中时你不需要 using对于那个命名空间。只需删除 using -陈述。

using System;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityStandardAssets.CrossPlatformInput; // remove this line
namespace UnityStandardAssets.CrossPlatformInput
{
public class AxisTouchButton : MonoBehaviour, IPointerDownHandler, IPointerUpHandler
{
...
}
}

这适用于两个源代码文件。

顺便说一句:属于同一命名空间的类也应该位于同一目录中。

关于c# - 无法在 C# 中使用命名空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42951524/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com