can i reference a script contained in a different namespace?

I have 3 folders in my project, named scripts, photon and standard assets. Now I need to make a reference from the standard assets folder to a script in the 'scripts' folder, which is possible only if I copy the folder into the standard assets(because it has a different namespace).But I get an error with the photon.So is there a way to make a reference without copying the folder?

 using UnityEngine;
 namespace UnityStandardAssets.CrossPlatformInput
{
public class ButtonHandler : MonoBehaviour
{  
  public  wepScript  ws; //error cannot find  wepScript 
}
}


  using UnityEngine;
  using System.Collections;

 public class wepScript : MonoBehaviour {
                   }

Upvotes: 0

Views: 4563

Answers (1)

Ramazan Kürkan
Ramazan Kürkan

Reputation: 156

Actually, namespace is not something related to the Unity. You can use whatever namespace or code in your classeses. You just need to include the namespace via using.

using UnityEngine;
using System.Collections;

For example: I have a script under Standard Assets folder called Weapon.

using UnityEngine;
namespace FooNamespace
{
    public class Weapon : MonoBehaviour {

        public void LogMeUp()
        {
            Debug.Log("I have been called");
        }
    }
}

And then, I have GonnaCallWeapon script somewhere else.

using UnityEngine;

using FooNamespace;

public class GonnaCallWeapon : MonoBehaviour {
    public Weapon weapon;
    void Start () {
        weapon.LogMeUp();
        Debug.Log("I called LogMeUp");
    }
}
  • I have attached my Weapon, and GonnaCallWeapon scripts to an object in the hierarchy, and set up the weapon variable.

Example

Upvotes: 1

Related Questions