- Home /
Console telling me to assign something which is already assigned
This one is really doing my head in - not sure if I am missing something silly.
Straight to the code, which I only just started and already have this issue. The script is called Scoring.js:
var SpawnPoint : Transform;
public var prefabObject : GameObject;
private var clone : GameObject;
private var offset : Vector3;
var coins : int = 100;
var canSpawn : boolean = true;
function Start ()
{
}
function Update ()
{
offset = transform.position;
if(Input.GetKeyDown(KeyCode.Space) && coins >0)
{
clone = Instantiate(prefabObject, offset, transform.rotation);
coins --;
Debug.Log("Coins Left:" + coins);
}
}
function OnCollisionEnter(col: Collision)
{
//see if the coin hit the trigger for a win
if (col.gameObject.tag == "coinWin")
{
Debug.Log("CoinWin!");
}
}
So I have prefabObject assigned in the inspector but the console is spamming me with hundreds of warnings that I need to assign it. What am I doing wrong or what am I misunderstanding?
Edited - forgot to include the error message:
"The variable prefabObject of 'Scoring' has not been assigned. You probably need to assign the prefabObject variable of the Scoring script in the inspector."
Thanks!
If when looking at the variable 'prefabObject' in the inspector it is assigned, check to see if you have other copies of this script unintentionally attached to other game objects.
I the prefab assigned from the project view or scene? $$anonymous$$ake sure its from project view
Answer by Mattolio · Feb 27, 2014 at 10:13 AM
The scoring script was also on the coin prefab. I feel stupid - but relieved to have found it. Thanks Robertbu!