Here is what I am trying to do. I have a gameobject. When a box collides with it, it should spawn another gameobject. I followed this link http://unity3d.com/support/documentation/Manual/Instantiating%20Prefabs.html . My code is pasted below:
var purpleTriangleBottomOuterCornerMelty : GameObject;
function OnCollisionEnter(event : Collision) {
Debug.Log("collision " + name);
createMelty(name, transform.position);
}
function createMelty(objectName: String, objectCoords: Vector3) {
Debug.Log("instantiating " + meltyMappingList[objectName]["rotation"]);
Instantiate(purpleTriangleBottomOuterCornerMelty, objectCoords, Quaternion.Euler(0, meltyMappingList[objectName].rotation, 0));
}
I have set the purpleTriangleBottomOuterCornerMelty variable to the prefab that I want to spawn, in the inspector of the object containing this script. But the Instantiate gives me a NullReferenceException. Apologies if I've missed something obvious, but I'm a total noob.
PS The above script is in my spawning object. I have a number of spawing objects, and want to spawn a different GameObject depending on the spawning object, so I made a mapping object (not included in the code) to map spawning object name to spawnee object.
with this info I can only guess. can you instaniate this prefab in another script? can you instantiate a cube in this script! can you show the entire script and paste in the error message? It is probably something simple, but not obvious from the info in the question...
– loopyllama