void SpawnObject() { GameObject o = Instantiate(spawnObject); //instantiate object BotLogic bl = o.GetComponent(typeof(BotLogic)) as BotLogic; //get logic component if (bl != null) { bl.SetPlanet(spawnAtTarget); //add spawn target to logic component } }