- Home /
How to set a Transform variable with code (C#)
I'm trying to make a game where enemy will be generated at a random place when someone starts it, and therefore I need to set a Transform variable to a cube called "Player". Is it possible and how would I do it?
Answer by BrandSpankingNew · Apr 17, 2017 at 07:31 PM
A simple approach would be to use the GameObject.Find syntax. https://docs.unity3d.com/ScriptReference/GameObject.Find.html Using that approach you could then easily determine the transform of the cube.
Perhaps you could even study the Transform.Find syntax. https://docs.unity3d.com/ScriptReference/Transform.Find.html
There are many examples, probably thousands of examples, available that a simple google search will serve to help eliminate your problem. Most of those search results will lead back to this forum.
Answer by Cuttlas-U · Apr 16, 2017 at 07:59 PM
public Transform myTransform;
any object in unity has Transform Component; thats the one that show the positions and rotaition or scale of an object;
more question u can ask me in my gmail : savajjad@gmail.com
Answer by RealGamesStudio · Apr 19, 2017 at 06:23 PM
Hello! It actually quite simple -
public/private Transform name
About the random place, there are many ways to do that. The first thing that comes to my mind it using Random.insideUnitSphere
I hope that helps. I wish you a great day :))