This question is slightly disjointed from one I asked yesterday, but is an extension in a couple ways.
I’ve got some spheres being instantiated randomly about the map. I only do it for the first 200 frames via manipulating update. I have a gameobject that initializes a set amount of spheres randomly about the map. Here’s that code:
var spherePick : Transform;
private var count : int;
count = 0;
function Update ()
{
if( count <= 200 )
{
var A = Random.Range(0.0, 500.0);
var B = Random.Range(0.0, 500.0);
var C = Random.Range(0.0, 500.0);
Instantiate(spherePick, Vector3 (A, B, C), Quaternion.identity );
count++;
}
}
The problem comes from attempting to use similar code on my first person controller player character. When the PC picks up a sphere I want more to spawn randomly on the map. Keep in mind this is all using the same prefab. So, I have the following function and variable inside my script that handles the pickups.
var spherePick : Transform;
function create ( amount : int )
{
var count : int = 0;
while ( count <= amount )
{
var A = Random.Range(0.0, 500.0);
var B = Random.Range(0.0, 500.0);
var C = Random.Range(0.0, 500.0);
Instantiate(spherePick, Vector3 (A, B, C), Quaternion.identity );
}
Debug.Log("New Spheres Spawned!");
}
So the problem is, whenever my PC tries to pick up (triggered inside OnControllerColliderHit via recognizing collision with a the prefab’s tag) a sphere, it crashes when trying to generate more. That is to say, the Update() script generates the spheres properly, and the spheres can be picked up. However, adding in the create() function now crashes unity whenever I try to pick up a sphere
Not really sure how or why this is going on. I saw some stuff suggesting that maybe my transformed vars needed to be private. I tried this and didn’t have any luck. Not sure how I can go about debugging an issue like this either. Something I’ve been wondering is if I have my parameter in create defined correctly. What’s there in the code is simply the latest thing I’ve tried. I’ve tried create( int amount ) create( amount ) create( int : amount) all to no avail.
EDIT: Seeing some formatting issues with the first chunk of code… looks OK in preview and it isn’t fixing itself, I apologize for that.