Hi, so I have my game project where the player is asked questions, responds by going through doors, and it instantiates a new room prefab on the other side of the door for the player to go through, however I’m having an issue where the old room and text that was created for it still linger and cause some confusion for the player and obscure the part of the new room and new question text.
[17449-screen+shot+2013-11-05+at+4.04.17+am.png|17449]
I’m not exactly sure what to do in this case. I’m not sure how to tell the mesh render for the previous room to turn off, delete, or become transparent to some degree when the player passes through the door or triggers a condition. I need some solution to at the very least get rid of the text from the previous room. The text, which is generated by reading a text file, is being generated through a script that goes like this.
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], 10 );
textMesh.renderer.material = ArialFont.material;
//Answers
GameObject door = gameObj;
textMesh.transform.rotation = door.transform.rotation;
textMesh.transform.position = new Vector3(door.transform.position.x - 6, door.transform.position.y + 10, 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.qNum + ") " + content.question, 20 );
textMesh2.renderer.material = ArialFont.material;
textMesh2.transform.rotation = door.transform.rotation;
textMesh2.transform.position = new Vector3(door.transform.position.x - 8, door.transform.position.y + 20, door.transform.position.z); //- cube.renderer.bounds.size.x / 2
textMesh2.transform.Rotate(Vector3.up, -90, Space.Self);
doOnceOnly++;
}
else {
doOnceOnly++;
}
doorAnswer++;
Also, after the first room, for some reason, the Question text is always off to the side instead of centred and I can’t seem to figure out why. Any ideas on what exactly I should do in this situation?