我正在尝试在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
,但我无法在Unity Monodevelop编辑器中的AxisTouchButton.cs
中获取该名称空间。
P.S。 :这两个文件都位于不同的目录中。
任何人都可以告诉我命名空间有什么问题吗?
谢谢, 罗希特夏尔
答案 0 :(得分:1)
当您的类已经在命名空间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
{
...
}
}
这适用于两个sourcscode文件。
顺便说一句:拥有属于同一名称空间的类也应该位于同一目录中。