Hi, Im writing a framework in Unity3D C#, consisting mostly of hardware input, that will be used by other game developers.
I wonder if there is any best practice. For instance I am currently using public GameObjects on a main-script so that the GameDeveloper can drag GameObjects on these public variables if he wants them to be controlled by the hardware.
Example:
public GameObject GOCube1 = null;
public GameObject GOCube2 = null;
void Update() {
GOCube1.Transform.position = HardwareInput.Cube1Position();
GOCube2.Transform.position = HardwareInput.Cube2Position();
}
I found, that if the first public GameObject e.g. GOCube1 is not assigned, because the develop forgets to drag the object into the scrip , Unity won’t execute the code that comes afterwards, eg. the transform of OGCube2. However the project still executes. I find this very confusing for the game developer, because now some objects react to the hardware inout (Cube1) but some don’t (Cube2).
Hence, I am thinking about using the Find function instead.
public GameObject GOCube1 = null;
public GameObject GOCube2 = null;
void Start(){
GOCube1 = GameObject.Find ("Cube1");
GOCube1 = GameObject.Find ("Cube2");
}
void Update() {
GOCube1.Transform.position = HardwareInput.Cube1Position();
GOCube2.Transform.position = HardwareInput.Cube2Position();
}
So if the game developer forgets to create an object Cube1, the project will simply not execute. This should make debugging a bit more straightforward.
What do you think?
PS: Should I rather use Public Transform instead of Public GameObject if I only manipulate positions?