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;
}