Can't drag Object into Inspector?

So I have an object called Koth Pole. I want to put it in the inspector variable KOTH Pole, but when I try to do so, it has the dark circle with a line slashed through it! Anyone know why I can’t do it?

The script with KOTH Pole variable.

using UnityEngine;
using UnityEngine.Networking;

public class PlayerShoot : NetworkBehaviour {

    private const string PLAYER_TAG = "Player";
    private const string POLE_TAG = "HillObject";


    public static int damage;
    public static float range;
    public GameObject KOTHPole;
    public KothPoleHealth kothHealth;

    [SerializeField]
    private Camera cam;

    [SerializeField]
    private LayerMask mask;

    void Start()
    {
//        if (PolePlacer.ourPole != null)
//        {
//            PolePlacer.ourPole = theKothPole;
//        }
        range = 10000f;
        if (cam == null)
        {
            Debug.LogError ("PlayerShoot: No camera referenced!");
            this.enabled = false;
        }

    }

    void Update()
    {
        if (Input.GetButtonDown ("left click"))
        {
            Shoot ();
        }
    }


    [Client]
    void Shoot()
    {
        RaycastHit _hit;
        if (Physics.Raycast(cam.transform.position, cam.transform.forward, out _hit, range, mask))
        {
            if (_hit.collider.tag == PLAYER_TAG)
            {
                CmdServerCallRpc (_hit.collider.name, damage);
//                PlayerShot (_hit.collider.name, weapon.damage);
            }
        }

        if (Physics.Raycast(cam.transform.position, cam.transform.forward, out _hit, range, mask))
        {
            if (_hit.collider.tag == POLE_TAG)
            {
                print ("hit pole");
                CmdServerCallRpcPoleDamage (damage);
                //                PlayerShot (_hit.collider.name, weapon.damage);
            }
        }
    }


    [Command]
    void CmdServerCallRpc (string _playerID, int _damage)
    {
        RpcServerPlayerShot (_playerID,_damage);

    }

    [Command]
    void CmdServerCallRpcPoleDamage (int _damage)
    {
        RpcServerPoleShot (_damage);

    }

    [ClientRpc]
    void RpcServerPlayerShot (string _playerID, int _damage)
    {
            Debug.Log (_playerID + " has been shot.");

            Player _player = GameManager.GetPlayer (_playerID);
            _player.RpcTakeDamage (_damage);
    }

    [ClientRpc]
    void RpcServerPoleShot (int _damage)
    {
  
        kothHealth = KOTHPole.GetComponent<KothPoleHealth> ();
        kothHealth.RpcTakePoleHealth (_damage);
    }


//    void PlayerShot (string _playerID, int _damage)
//    {
//        Debug.Log (_playerID + " has been shot.");
//
//        Player _player = GameManager.GetPlayer (_playerID);
//        _player.RpcTakeDamage(_damage);
//    }
}

P.S. The object I want as the variable is in the game, while the object with the script is a prefab in assets, and if I bring the prefab into the game I can set the variable, but not when in asset folder!

Yep. Prefabs can’t reference objects in the scene. Consider that the scene you’re editing now might not be the current scene when the prefab is needed …typical Unity games have several (or many) scenes. So, it wouldn’t make any sense for prefabs to have references to scene objects.

2 Likes

Ok, do you know of anyway I could work around this? I’ll try instantiating one to the scene

I assume your instantiating these objects in a script somewhere? if you are make sure you keep a handle that the Instantiate returns like this:
GameObject myObject = (GameObject)Instantiate(MyPrefab);

if KothPole is the one Instantiating these things its easy just
myObject.KOTHPole = this;

otherwise you need to have a way to get a hold of the KOTHpole object. You could tag it and use:
myObject.KOTHPole = GameObject.FindGameObjectWithTag(“Tag”);

Ok I got it, using this script I was able to copy one from prefab, and then put it in the scene. I don’t know why that didn’t work last time I tried but thank you all for helping me!

using UnityEngine;
using System.Collections;

public class PolePlacer : MonoBehaviour {

    public GameObject MyPrefab;

    public static GameObject myObject;


    void Start ()
    {
        myObject = (GameObject)Instantiate (MyPrefab);
    }

}