Rohit
Rohit

Reputation: 189

Not able to use namespace in C#

I am trying to develop a game in Unity editor. I'm not able to use the namespace from one script into another. Please find the scripts below.

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();
        }
    }
}

The script CrossPlatformInputManager has namespace UnityStandardAssets.CrossPlatformInput, but I'm not able to get that namespace in AxisTouchButton.cs in Unity Monodevelop editor.

P.S. : Both the files are located in different directory.

Can anybody please tell me what's wrong with the namespace?

Thanks, Rohit

Upvotes: 1

Views: 760

Answers (1)

MakePeaceGreatAgain
MakePeaceGreatAgain

Reputation: 37000

When your class already is in the namespace UnityStandardAssets.CrossPlatformInput you don´t need a usingfor that namespace. Simply remove the using-statement.

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

This apllies to both sourcscode-files.

Btw.: having classes that belong into the same namespace should also be located in the same directory.

Upvotes: 1

Related Questions