I'm java programmer and I'm new with Unity. I'm writing a grid that lays on a Plane object. The aim is to separate grid-based logic from Unity 3D coordinate system. Actually the game speaks in terms of grid positions, so I need a code that converts game coordinate system to/form Unity coordinate system (World position). Since the position of Plane object may be modified (rotated, moved, etc), I want to "mark" Plane left bottom corner. In this case I will be able to convert one coordinate system to another at any time, since form the game point of view the "marker in game" coordinates is 0,0 (2D). Unfortunately my code doesn't work.
Could you please say me what is wrong (the properties of "marker" are not changed when Plane is moved)?
public class GridManager: MonoBehaviour {
GameObject ground;
GameObject marker;
...
void attachMarker() {
//get substrate (plane)
GameObject ground = getGround();
//create marker
GameObject marker = new GameObject();
//set marker position to left bottom corner
marker.transform.position.x = ground.transform.position.x - ground.transform.localScale.x/2;
marker.transform.position.z = ground.transform.position.z - ground.transform.localScale.z/2;
marker.transform.position.y = 0;
//set marker size
marker.transform.localScale = new Vector3(0,0,0);
//set marker name (will be used for search)
marker.name = "LB_Marker";
//set marker to be child of ground
marker.transform.parent = ground.transform;
//store it
this.marker = marker;
}
}