Get script from var GameObject child

Hey

I’m working on a TD game, where i have a “ShopController”, and have run into a problem. I’m getting this error:

I have to load the Gun spec from the guns script named “Minigun”,

Some of the ShopController script:

GUI.Box(Rect((Screen.width-200-10),(Screen.height-320-40-110), 200,320), "Store");
		if(ShopController.UpgradeActive == true)
		{
			if(ShopController.SelectedField == "LeftGround")
			{ 
				var gunSpec1 = masterscript.LeftSideGroundObject.gameObject.GetComponentInChildren(Minigun);
				GUI.Label(Rect((Screen.width-200),(Screen.height-320-120+5), 180,25), "Now:",BoldLabel);
				GUI.Label(Rect((Screen.width-200),(Screen.height-320-120+25), 180,25), "SPS: " + gunSpec1.SPSUp[gunSpec1.gunLevel+1]);
				GUI.Label(Rect((Screen.width-200),(Screen.height-320-120+45), 180,25), "Damage:");
				GUI.Label(Rect((Screen.width-200),(Screen.height-320-120+65), 180,25), "Range:");
				GUI.Label(Rect((Screen.width-200),(Screen.height-320-120+85), 180,25), "Miss:");
				GUI.Label(Rect((Screen.width-200),(Screen.height-320-120+120+5), 180,25), "Next:",BoldLabel);
				GUI.Label(Rect((Screen.width-200),(Screen.height-320-120+25+120), 180,25), "SPS:");
				GUI.Label(Rect((Screen.width-200),(Screen.height-320-120+45+120), 180,25), "Damage:");
				GUI.Label(Rect((Screen.width-200),(Screen.height-320-120+65+120), 180,25), "Range:");
				GUI.Label(Rect((Screen.width-200),(Screen.height-320-120+85+120), 180,25), "Miss:");
				if(GUI.Button(Rect((Screen.width-200),(Screen.height-320-120+85+165), 180,30), "Upgrade"))
				{}
			}
		}

And the GameObject var from MasterScript

var LeftSideGroundObject : GameObject;

Can someone help me? :slight_smile:

Do you have another GameObject variable in the script called Minigun?

You clearly have a child called minigun that is a game object. I suppose you also have a script called minigun…? Anyway, you will need to rename one or the other, as the find function dont know which one you want to get, and it gets a bit messy.

Really thanks, i had a prefab called “Minigun” that i change to “MinigunPrefab” and then it worked :slight_smile: