I am working my way through some tutorials on working in unity with C# and I have a question about the following code:
//Instantiate a new muzzleFlashPrefab object and store in the variable clone Transform clone = Instantiate (muzzleFlashPrefab, firePoint.position, firePoint.rotation) as Transform; // set the new objects parent to firepoint. clone.parent = firePoint; //create a random float and use this as the size of clone float size = Random.Range (0.3f, 0.6f); clone.localScale = new Vector3 (size, size, size); //Then destroy the muzzleFlash Destroy (clone.gameObject, 0.02f);
My question is this. Obviously the code randomises the size of the “muzzle flash” but it does so after the object has been instantiated. Now this codes works but I am wondering if anyone can tell me why? Surely if the object has been already been instantiated at default size this shouldn’t do anything? Or am I instantiating it (so it appears on the screen) then changing the size so quickly I don’t notice the original size before deleting it?
Apologies if this is a silly question I feel like I’m missing something here.