- Home /
main camera destroying in editor but not in android
i am trying to spawn a player with a first person controller when the user presses any one of the two gui buttons on my amin camera.this works fine in the editor and the camera gets destroyed but in android it still shows the main camera view without switching to the players camera.the gui buttons also get activated and the debug.log gets executed,but the camera just does nt switch or destroy.please help! my code:
//gui logic
var originalWidth = 640.0;
var originalHeight = 400.0;
private var scale: Vector3;
var my:GUISkin;
//player
var player:GameObject;
//positions
var pos1:GameObject;
var pos2:GameObject;
function OnGUI()
{
GUI.skin=my;
scale.x = Screen.width/originalWidth;
scale.y = Screen.height/originalHeight;
scale.z = 1;
var svMat = GUI.matrix;
GUI.matrix = Matrix4x4.TRS(Vector3.zero, Quaternion.identity, scale);
if(GUI.Button (Rect (originalWidth - 430,originalHeight - 350,50,50), "ROOF:1"))
{
player.transform.position=pos1.transform.position;
player.transform.rotation=pos1.transform.rotation;
player.SetActive(true);
transform.GetComponent(Camera).enabled=false;
GameObject.Destroy(gameObject);
Debug.Log("Spawning");
}
if(GUI.Button (Rect (originalWidth - 200,originalHeight - 350,50,50), "ROOF:2"))
{
player.transform.position=pos2.transform.position;
player.transform.rotation=pos2.transform.rotation;
player.SetActive(true);
transform.GetComponent(Camera).enabled=false;
GameObject.Destroy(gameObject);
Debug.Log("Spawning");
}
if(GUI.Button (Rect (originalWidth - 640,originalHeight - 400,50,50), "Back"))
{
Application.LoadLevel(0);
}
GUI.matrix = svMat;
}
an untagged camera named as $$anonymous$$ain Camera under a gameobject called map
Answer by DiegoSLTS · Jun 27, 2015 at 12:57 AM
Change the tag of the new camera to MainCamera after destroying the main camera.
When you remove the MainCamera in the editor, the image drawn by that camera gets cleared, but on builds it doesn't work the same way and you start getting this weird behaviours.
i did that but it still shows the previous camera view
Your answer
![](https://koobas.hobune.stream/wayback/20220613201426im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Reading XML Data for andriod 1 Answer
Joystick isn't recognize by Unity when i activate CardBoard option 0 Answers
Make camera follow an instantiated object 1 Answer
Why do get lag when rotating a camera on android ? 0 Answers
Screenshot function not working properly ,it records button on UI ? 0 Answers