// Update is called once per frame
    void Update()
    {
        if (www != null)
        {
            if (www.isDone)
            {
                bool res;
                bool.TryParse(www.text, out res);
                if (res == true)
                {
                    masterController.getStorage().storeBoolValue("UserIsConfirmed", true);
                    masterController.saveGame(false);
                }
                else
                {
                    // tough titty
                }
                Destroy(this.gameObject);
            }
        }
        else
        {
            ++nullFrames;
        }

        if (nullFrames >= MaxNullFrames)
        {
            Destroy(this.gameObject);
        }
    }
 // Update is called once per frame
 void Update()
 {
     if (www != null)
     {
         if (www.isDone)
         {
             if (state == 0)
             {
                 bool res;
                 bool.TryParse(www.text, out res);
                 if (res == true)
                 {
                     mcRef.getStorage().storeBoolValue("UserIsConfirmed", true);
                     mcRef.saveGame(false);
                     mcRef.setActivityFinished();
                 }
                 else
                 {
                 }
                 www   = null;
                 state = 1;
             }
             else
             {
                 finishActivity();
                 www = null;
             }
         }
     }
 }
    public void killLevel(int l)
    {
        mc.loadGame(true);
        mc.saveGame(false);
        SceneManager.LoadScene("root");
        //ds.storeBoolValue ("PlayerMustMaterialize", true);
        //ds.storeStringValue ("ReentryCondition", "");

        // NO, CHAVAL, SISTEMA DE CHECKPOINTS

        /*
         *      switch (l) {
         *      // Cambiar todo esto para no tener que inicializar tantos valores, es un pestazo
         *      case 1: // clear all stored values from Level1
         *              ds.storeBoolValue ("IsDoorbrownDoorGeoOpen", false);
         *              ds.storeBoolValue ("IsDoorgreyDoorGeoOpen", false);
         *              ds.storeBoolValue ("IsDoorblueDoorGeoOpen", false);
         *              ds.storeBoolValue ("IsDoorgreenDoorGeoOpen", false);
         *              ds.storeBoolValue ("IsDoorgreyDoorGeo (1)Open", false);
         *              ds.storeBoolValue ("IsDoorgreyDoorGeo (2)Open", false);
         *              ds.storeBoolValue ("IsDoorgreyGeoCasa2", false);
         *              ds.storeBoolValue ("IsDoorgreyGeoCasa3", false);
         *              ds.storeBoolValue ("IsDoorgreyGeoCasaInsultador", false);
         *              ds.storeBoolValue ("IsDoorgreyGeoCasaTraficante", false);
         *              ds.storeBoolValue ("IsDoorgreyGeoCasa4", false);
         *              ds.storeBoolValue ("IsDoorgreyGeoCasa5", false);
         *              ds.storeBoolValue ("IsLeverOn", false);
         *              ds.storeBoolValue ("IsLeverOn2", false);
         *              ds.storeFloatValue ("CoordsLevel1/Plane0_exteriorX", 0.0f);
         *              ds.storeFloatValue ("CoordsLevel1/Plane0_exteriorY", 0.0f);
         *              ds.storeFloatValue ("CoordsLevel1/Plane0_exteriorZ", 0.0f);
         *              ds.storeIntValue ("Orientation", 0);
         *              ds.storeIntValue ("Level1ShadowWaveNumber", 0);
         *              ds.storeBoolValue ("Level1BlueMirrorDepleted", false);
         *              ds.storeBoolValue ("Level1BlueMirrorActivated", false);
         *              ds.storeBoolValue ("Level1BrownMirrorDepleted", false);
         *              ds.storeBoolValue ("Level1BrownMirrorActivated", false);
         *              ds.storeBoolValue ("Level1YellowMirrorDepleted", false);
         *              ds.storeBoolValue ("Level1YellowMirrorActivated", false);
         *              ds.storeBoolValue ("Level1GreenMirrorDepleted", false);
         *              ds.storeBoolValue ("Level1GreenMirrorActivated", false);
         *              SceneManager.LoadScene ("Scenes/Level1/Level1Plane0_exterior");
         *              break;
         *
         *      default:
         *
         *              break;
         *      }*/
    }
    new void Start () 
	{
		WalkingMode ();

		SelectHUD ();

		GameObject inetGO = GameObject.Find ("RedIntercon");
		if (inetGO != null) {
			iNetRef = inetGO.GetComponent<interconNetwork> ();
		}

		speed = PLAYERSPEED;

		GameObject mgo = GameObject.Find ("MirrorObject");
		if(mgo != null) {
			mirrorObject = mgo.GetComponent<MirrorObject> ();
		}

		agent = GetComponent<UnityEngine.AI.NavMeshAgent> ();
		if (agent != null) {
			agent.enabled = false;
			agent.updateRotation = false;
		}

		r = GetComponent<Rigidbody> ();
		unblockControls ();

		cam = GameObject.Find ("CameraLerp").GetComponent<CameraManager> ();
		masterControllerRef = GameObject.Find ("MasterController");
		mcsRef = masterControllerRef.GetComponent<MasterControllerScript> ();
		rosetta = GameObject.Find ("Rosetta").GetComponent<Rosetta> ();
		ds = mcsRef.getStorage ();

		// check music
		if (!ds.retrieveBoolValue ("Is" + levelRef.locationName + "MusicPlaying")) {
			mcsRef.selectMixer (0);
			string lvl = levelRef.locationName.Substring (5, 1);
			//mcsRef.playMusic (int.Parse(lvl));
			mcsRef.setVolume (1.0f);
			ds.storeBoolValue ("Is" + levelRef.locationName + "MusicPlaying", true);
		}

		spawningShadowElapsedTime = noSpawningShadowTime;

		state2 = PlayerState.idling;

		interactionQuadRef.GetComponent<SpriteRenderer> ().enabled = false;

		interaction = Interaction.None;
		interactee = null;
		backupInteractee = null;

		direction = PlayerDirection.front;

		playerRendRef = spriteQuadRef.GetComponent<SpriteRenderer>();
		playerMatRef = playerRendRef.material;
		otherPlayerRendRef = spriteQuadBehindRef.GetComponent<SpriteRenderer> ();
		otherPlayerMat = otherPlayerRendRef.material;

		ascendPos = 0.0f;
		ascendSpeed = 0.0f;
		ascendAccel = 45.0f;

		elapsedTime = 0.0f;

		if (ds.retrieveBoolValue ("PlayerMustMaterialize")) 
		{
			state = PlayerState.dematerialized;
			playerMatRef.color = new Color (1, 1, 1, 0);

			blocked = true;
		} else {
			state = PlayerState.idling;
			//opacity = 1.0f;
			playerMatRef.color = new Color (1, 1, 1, 1);
		}

		float x, y, z;
		x = ds.retrieveFloatValue ("Coords" + levelRef.locationName + "X");
		y = ds.retrieveFloatValue ("Coords" + levelRef.locationName + "Y");
		z = ds.retrieveFloatValue ("Coords" + levelRef.locationName + "Z");
		Debug.Log ("<color=red>Player coords retrieved: (" + x + "," + y + "," + z + ") on "+levelRef.locationName+" </color>");
		int orientation;
		orientation = ds.retrieveIntValue ("Orientation");
		Debug.Log ("<color=green>Player orient. stored: (" + orientation + ") on "+levelRef.locationName+"</color>");
		setOrientation (orientation);
		if ((x == 0) && (y == 0) && (z == 0)) 
		{
			if (GameObject.Find ("PlayerStart")) 
			{
				Vector3 newPos = GameObject.Find ("PlayerStart").transform.position;
				this.transform.position = newPos;
			}
			mustSnapToPlayerStart = 60;
		}
		if ((x != 0.0f) && (y != 0.0f) && (z != 0.0f)) {
			Vector3 newPos = new Vector3 (x, y, z);
			this.transform.position = newPos;
			mustSnapToPlayerStart = 0;
		}
		levelRef.loadPhysicalCameraPosition ();
		cam.Initialize ();
		string nameOfFollowingCharacter = ds.retrieveStringValue ("FollowingChar");
				if (!nameOfFollowingCharacter.Equals ("")) {
					GameObject charaGO = GameObject.Find (nameOfFollowingCharacter);
					if (charaGO != null) {
						float xc = ds.retrieveFloatValue ("FollowerRelativeCoordsX");
						float xy = ds.retrieveFloatValue ("FollowerRelativeCoordsY");
						float xz = ds.retrieveFloatValue ("FollowerRelativeCoordsZ");
						CharacterGenerator chara = charaGO.GetComponent<CharacterGenerator> ();
						if (chara != null) {
							chara.warpToRelativeToPlayer (new Vector3 (xc, xy, xz));
							chara.setAutopilotAbsolute (true);
							chara.preventAwake = true;
							chara.stopAllEvents ();
							chara.startFollowingPlayer ();
							chara.markedAsStartFollowing = true;
						}
					}
				}


		levelRef.Start ();
		string retAct = ds.retrieveStringValue ("ReturnFromActivity");
		if (retAct.Equals ("Well")) {
			int res = ds.retrieveIntValue ("ActivityResult");
			if (res > 0) {
				int red = ds.retrieveIntValue ("RedManaObtained");
				int blue = ds.retrieveIntValue ("BlueManaObtained");
				if (red > 0) {
					string msg = rosetta.retrieveString (recoveryStrings.getStringId (0)) + red;

					levelRef._wm_alert (msg);
				} else {
					//string msg = rosetta.retrieveString (recoveryStrings.getStringId (1)) + blue;
					string s1 = recoveryStrings.getStringId (1);
					string s2 = rosetta.retrieveString (s1);
					string s3 = s2 + blue;
					levelRef._wm_alert (s3);
				}
			} else {
				//levelRef._wm_alert (rosetta.retrieveString (recoveryStrings.getStringId (2)));
				string s1 = recoveryStrings.getStringId (2);
				string s2 = rosetta.retrieveString (s1);
				levelRef._wm_alert (s2);
			}
		} else if (retAct.Equals ("Main-1")) {
			string lvl = levelRef.locationName.Substring (0, 6);
			ds.storeIntValue (lvl + "SpawnedShadows", 0);
		}

		if (levelRef.floor == 0)
			ds.storeStringValue ("ReturnFromActivity", "Main");
		else if (levelRef.floor == -1)
			ds.storeStringValue ("ReturnFromActivity", "Main-1");
		else if (levelRef.floor == 1)
			ds.storeStringValue ("ReturnFromActivity", "Main+1");

		height = this.transform.position.y - 6;

		externalForce = Vector3.zero;


		mcsRef.saveGame (false); // save every time the player is spawned (change location)

		/*
		 * 
		 * Check reentrancy
		 * 
		 */

		string reentryCondition = ds.retrieveStringValue ("ReentryCondition");

		if (reentryCondition.Equals ("MirrorActivation")) {
			mirrorActivationDelaying = true;
			//camRef.GetComponent<CameraLookAt> ().enabled = false;
			cam._wm_disableLookAt ();

		} else
			mirrorActivationDelaying = false;


		if (reentryCondition.Equals ("Inventory")) {
			ds.storeStringValue ("ReentryCondition", ""); // consume condition
			int _num = ds.retrieveIntValue ("InventoryLevel");
			inventory.reenter (_num);
		}

        if(levelRef.retrieveBoolValue("Meditating"))
        {
            levelRef.storeBoolValue("Meditating", false);
            meditatingRemaining = 4.5f;
            playerRendRef.sprite = Meditating[0];
            otherPlayerRendRef.sprite = Meditating[0];
        }
        else
        {
            meditatingRemaining = 0.0f;
        }

        /*
		 * 
		 * Reset reentry condition
		 * 
		 */

        started = true;
	}