Hello there.
My game features a player answering questions by going through a door, corresponding with their answer, which spawns a new room and a new question. There are 3 paths the player can take. You can see how the first level looks in the first image I've uploaded. (
http://www.polycount.com/forum/attachment.php?attachmentid=14564&stc=1&thumb=1&d=1386298182)
Right now, my problem is the positioning of the text for the questions and answers. As the game goes on, the positioning begins to misalign when its spawned in the instantiated room, especially if the player chooses either the left of right doors. You can see this misalignment in the second picture I uploaded. (
http://www.polycount.com/forum/attachment.php?attachmentid=14565&stc=1&thumb=1&d=1386298237)
I'm not exactly sure how to align it properly. The code for this aspect of my game was written by a friend who is currently unavailable and while I understand the much of what the code he wrote does, I have no idea how to fix it. Here is the part of the code that handles the TextMeshes used for the Question and answers. Any ideas on how to correct this or how to properly anchor it to a separate object?
Note: This is only a minor detail in the grand scheme of things you are free to ignore, but is there anyway to make the text alignment within the text itself centred?
Note: Here's a test video showing the game:
https://vimeo.com/80639741 int doorAnswer = 0;
int doOnceOnly = 0;
foreach (var gameObj in FindObjectsOfType(typeof(GameObject)) as GameObject[]) {
if (gameObj.name == "Body") {
objText.Add (new GameObject ("TextObject"));
TextMesh textMesh = objText.Last ().AddComponent<TextMesh> ();
Font ArialFont = (Font)Resources.GetBuiltinResource (typeof(Font), "Arial.ttf");
textMesh.font = ArialFont;
//textMesh.text = "Hello World!";
textMesh.text = Util.WordWrap (/*"A" + (doorAnswer + 1) + ") " +*/ content.answers[doorAnswer].text, 20);
textMesh.renderer.material = ArialFont.material;
textMesh.fontStyle = FontStyle.Bold;
//Answers
GameObject door = gameObj;
textMesh.transform.rotation = door.transform.rotation;
textMesh.transform.position = new Vector3 (door.transform.position.x - 8, door.transform.position.y + 9, door.transform.position.z); //- cube.renderer.bounds.size.x / 2
textMesh.transform.Rotate (Vector3.up, -90, Space.Self);
//0th is left door, 1th center, 2nd right
if (doOnceOnly == 1) {
//put question above center door
//Question
objText.Add (new GameObject ("TextObject"));
TextMesh textMesh2 = objText.Last ().AddComponent<TextMesh> ();
textMesh2.font = ArialFont;
textMesh2.text = Util.WordWrap ("Q" + content.index + ") " + content.text, 70);
textMesh2.renderer.material = ArialFont.material;
textMesh2.fontSize = 18;
textMesh2.fontStyle = FontStyle.BoldAndItalic;
textMesh2.transform.rotation = door.transform.rotation;
textMesh2.transform.position = new Vector3 (door.transform.position.x - 25, door.transform.position.y + 17, door.transform.position.z); //- cube.renderer.bounds.size.x / 2
textMesh2.transform.Rotate (Vector3.up, -90, Space.Self);
doOnceOnly++;
} else {
doOnceOnly++;
}
doorAnswer++;
}
}
}
Replies
It will always be the correct position and rotation of the door.
Ignore this . Would be something you would do later as you advance.