Edit 3:
i have managed to work out what exactly i'm attempting to do, and it only took 48 hours.. i need to create multiple objects, based on the same object, with different values. but i keep creating multiple objects that all get the same values.
foreach (float a in ListA)
{
Instantiate(Example); //so here i have also tried creating new game objects, they are created but wont render. and behave the same way as clone anyway. (can see their positions in the paused editor)
Example.transform.position = new Vector2(0f, up); // this works as i want it too.
Example.GetComponent<NewBehaviourScript>().SetSpeed(Assets.Class1.random.Next(20, 70) * 1f, Assets.Class1.random.Next(20, 70) * 1f, Assets.Class1.random.Next(20, 70) * 1f); //THIS is the issue.. it is passing the random values, but its is only passing the SAME random values to each instance. i have tried to .Add but it will just add multiple of the same script to the new object/clones. Adding this. doesnt really seem to matter.
up = up 40f;//works
}
i've tried creating the gameobjects different ways.. but it doesn't really matter. i wont be using random values in the end, i'm just using them as a test to make sure each object gets different values in the end.
CodePudding user response:
You need to use the result that is returned from the Instantiate command.
var instance = Instantiate(Example);
instance.transform.position = new Vector2(0f, up);
....
Currently you are modifying values on the prefab itself, and not the instantiated object, which is why you are not seeing the changes you intended to apply.
CodePudding user response:
soooooo.. my code worked all along.. after many many hours, i gave up. literally threw in the towel and was going to go to sleep. and as soon as my head hit the pillow.. "what if..."
anyway, the problem was static modifiers in the NewBehaviorScript portion. i fell really dumb now. but for anyone else with this issue.. check your sub script for static modifiers.