Hello,
Just started using C# due to it’s powerful regular expressions. I am running into problems that were quite easily solved in Unity JS.
I instantiate a prefab:
GameObject newMino = Instantiate(Resources.Load(“Prefabs/Mino”)) as GameObject;
Is there a way to instantiate at a certain location? If not, can you specify a position rather than translating it after instantiation? I.E.,
Transform t_newMino = newMino.GetComponent(typeof(Transform)) as Transform;
t_newMino.position = Vector3(5, 0, 0);
Lastly, the prefab has 4 materials. By default, the prefab uses the last material in the array. I want to change the active material to be, say, the first material in the array. How can I do this in C#? I have tried the following with no luck:
Renderer r_newMino = newMino.GetComponent(typeof(Renderer)) as Renderer;
r_newMino.renderer.material = r_newMino.renderer.materials[0];
and
Renderer r_newMino = newMino.GetComponent(typeof(Renderer)) as Renderer;
r_newMino.renderer.material = r_newMino.renderer.sharedMaterials[0];
Thanks!
-n