- Home /
Question by
Christian.Tucker · Sep 11, 2013 at 10:45 AM ·
return type
Cannot cast from source type to destination type? C#
Here's the void that's causing the error
public void SpawnUnit(Transform unit, string name, Vector3 pos, Quaternion rot, int pop) {
if((rsm.playerResources[ResourceManager.ResourceType.CurrPOP] + pop) <= rsm.playerResources[ResourceManager.ResourceType.MaxPOP]) {
tempObject = (GameObject)Instantiate(unit, pos, rot);
tempObject.name = name;
rsm.addResource(ResourceManager.ResourceType.MaxPOP, pop);
} else
Debug.Log ("Too much population shit");
}
Here's my script calling this.
DummyScript ds;
public Transform worker;
Transform myTransform;
// Use this for initialization
void Start () {
myTransform = transform;
ds = GameObject.FindGameObjectWithTag("ScriptManager").GetComponent<DummyScript>();
for(int i = 0; i <= 5; i++ )
ds.SpawnUnit(worker, "Worker", myTransform.position, myTransform.rotation, 1);
}
Comment
I think its because you can't cast a transform (the thing you are instantiating) to a GameObject. Not really sure what instantiating a Transform will accomplish either, should it not be a GameObject to start with?
Your answer
Follow this Question
Related Questions
How to make a "Type" variable? 1 Answer
Is there a way to return all your viaraibles and script to the way it was when the game started 0 Answers
Adding javascript to objects via scripting question. 0 Answers
Profiler.GetTotalAllocatedMemory Return 0 Answers
Adding javascript to objects via scripting question. 0 Answers