private void Awake() { instance = this; //DontDestroyOnLoad(gameObject); PlayGamesPlatform.Activate(); OnConnectionResponse(PlayGamesPlatform.Instance.localUser.authenticated); }
/// <summary> /// Try finding the player launcher /// </summary> private void GetPlayerLauncher() { // Finds the Player, and then the playerLauncher try { _playerLauncher = GameObject.FindGameObjectWithTag("Player").transform.Find("Shooting").GetComponent <launcher>(); } catch { Debug.Log("Could not find player launcher"); } }
// Update is called once per frame void Update() { //Event system //always present items MainCamupdate=GameObject.Find("Main Camera"); Camupdate=MainCamupdate.GetComponent<Camera>(); if (inLevel){ //if in a playable level //player/component declarations player=GameObject.Find("Rocket"); PlayerCam=GameObject.Find ("CamTarget"); Earth=GameObject.Find("Earth"); Indicator=GameObject.Find ("Indicator"); launcher=GameObject.Find("Launcher"); launchscript=launcher.GetComponent<launcher>(); //WHY IS THIS ONE TAKING SO LONG TO LOAD OR SOMETHING trajectory=GameObject.Find("Trajectory"); An=player.GetComponent<Animator>(); boxcoll=MainCamupdate.GetComponent<BoxCollider2D>(); TrajectoryMidpoint = GameObject.Find("TrajectoryMidpoint"); Launch = GameObject.Find("Launch"); } else { //menus exception GameStatus=8; } if (GameStatus == 0) { //Starting CamMode = false; if (initial0) { //to prevent multiple invokes CamOrig= new Vector3((StrongestPlanet.transform.position.x + player.transform.position.x) / 2, (StrongestPlanet.transform.position.y + player.transform.position.y) / 2, -10f); CamOrigZoom=0.5f * StrongestPlanetDist; Invoke("CamStart", 2);//Invoke a function to target onto rocket launch pad after 2 seconds initial0 = false; } } else if (GameStatus == 1) { //Explore if (resetalready) { //for some reason slips through when reset hit really early sometimes so reasigned CamOrig = new Vector3((StrongestPlanet.transform.position.x + player.transform.position.x) / 2, (StrongestPlanet.transform.position.y + player.transform.position.y) / 2, -10f); CamOrigZoom = 0.5f * StrongestPlanetDist; Camupdate.transform.position = new Vector3((StrongestPlanet.transform.position.x + player.transform.position.x) / 2, (StrongestPlanet.transform.position.y + player.transform.position.y) / 2, -10f); Camupdate.orthographicSize = CamOrigZoom; //functionalise resetalready = false; } //Allow freecam control, plus trajectory modification if (stratcam == false) { //CamMode = true; //set cam mode if (Input.touchCount == 1) { CamMode = true; //set cam mode CancelInvoke("CamStart"); touch = Input.GetTouch(0); if (touch.phase == TouchPhase.Began) { if (((TargetDetect(touch) == true) || (previousTargetDetect(touch) == true)) && (UiDetect(touch) == false)) { //check if touch is incident with target object //Launcher orientation manipulation if (touch.phase == TouchPhase.Began) { draginprogress = true; setActionCam(TrajectoryMidpoint); } Launcherrotate(launcher, touch); } else { // if its not incident then we want to have the camera drag capability possibly functionalise this code CamMode = true; Vector2 touchprev = touch.position - touch.deltaPosition; Vector2 touchmagnitude = touch.position - touchprev; Vector3 newpos = new Vector3(-touchmagnitude.x * 0.03f, -touchmagnitude.y * 0.03f, 0); Camupdate.transform.position += newpos; } } else if ((touch.phase == TouchPhase.Moved) || (touch.phase == TouchPhase.Stationary)) { if (draginprogress) { setActionCam(TrajectoryMidpoint); Launcherrotate(launcher, touch); } else { CamMode = true; Vector2 touchprev = touch.position - touch.deltaPosition; Vector2 touchmagnitude = touch.position - touchprev; Vector3 newpos = new Vector3(-touchmagnitude.x * 0.03f, -touchmagnitude.y * 0.03f, 0); Camupdate.transform.position += newpos; } } else if ((touch.phase == TouchPhase.Ended) || (touch.phase == TouchPhase.Canceled)) { draginprogress = false; if (inLevel) { trajectory.GetComponent<SpriteRenderer>().sprite = launchscript.trajectorytrans; } //also put in momentum code here? } } else if (Input.touchCount == 2) { //if two fingers are touching, meaning we want to pinch zoom CamMode = true; //set cam mode CancelInvoke("CamStart"); if (inLevel) { trajectory.GetComponent<SpriteRenderer>().sprite = launchscript.trajectorytrans; } Touch touchZero = touch; Touch touchOne = Input.GetTouch(1); Vector2 touchZeroPrevPos = touchZero.position - touchZero.deltaPosition; // Find the position in the previous frame of each touch. Vector2 touchOnePrevPos = touchOne.position - touchOne.deltaPosition; float prevTouchDeltaMag = (touchZeroPrevPos - touchOnePrevPos).magnitude; // Find the magnitude of the vector (the distance) between the touches in each frame. float touchDeltaMag = (touchZero.position - touchOne.position).magnitude; float deltaMagnitudeDiff = prevTouchDeltaMag - touchDeltaMag;// Find the difference in the distances between each frame. if (Mathf.Abs(deltaMagnitudeDiff * orthoZoomSpeed) >= 0.1f) { //ensure change is substantial to prevent flickering Camupdate.orthographicSize += deltaMagnitudeDiff * orthoZoomSpeed;// change the orthographic size based on the change in distance between the touches. } //Camupdate.orthographicSize = Mathf.Max(Camupdate.orthographicSize, 0.1f);// Make sure the orthographic size never drops below zero. Camupdate.orthographicSize = Mathf.Clamp(Camupdate.orthographicSize, 2f, DataPlay.maxzoomoutsize[Application.loadedLevel]); //clamp to ensure zooms } } else { setStratCam(); //need to consider reset ability } } else if (GameStatus == 2) { // Launching CancelInvoke("CamStart"); // incase time has been skipped CamMode = false; //back to the dynacam //CamTarget=PlayerCam.transform.position; if (stratcam == false) { //old suspense zoom in code /*if (initial) { CamZoom = 0.5f * dist; initial = false; } else { CamZoom -= 0.1f * Time.deltaTime; }*/ //need to get midpoint setActionCam(player); } else { setStratCam(); } } else if (GameStatus == 3) { //Launched CamMode = false; if (stratcam == false) { if (initiallaunched) { camhook = false; initiallaunched = false; } setActionCam(player); } else { setStratCam(); } if (Input.touchCount >= 1) { touch = Input.GetTouch(0);//gets the touch and assigns it to touch variable if (UiDetect(touch) == false) { //if the touch is not coincident with a UI element if (fuel > 0) { //if the rocket has fuel An.SetBool("Active", true); fuel = fuel - 1 * Time.deltaTime; Rigidbody2D x = player.gameObject.GetComponent<Rigidbody2D>(); Vector3 diff = Camera.main.ScreenToWorldPoint(touch.position) - player.transform.position; diff.Normalize(); float rot_z = Mathf.Atan2(diff.y, diff.x) * Mathf.Rad2Deg; player.transform.rotation = Quaternion.Euler(0f, 0f, rot_z - 90); x.AddRelativeForce(power, ForceMode2D.Impulse); } else { An.SetBool("Active", false); } } } else { //if nothing else is touched make sure to reset rocket power An.SetBool("Active", false); } } else if (GameStatus == 4) { //landed //not much to go in here at the moment as landing is buggy } else if (GameStatus == 5) { //Success //Application.LoadLevel(0); //placeholder for testing } else if (GameStatus == 6) { //Paused //eventually when freecam functionalised add here //make pause menue pop up //Consider a wipe function implementable that runs at initial of each gamestatus to ensure correct ui elements shown } else if (GameStatus == 7) {//destroyed/failed //reset cam back to initials //when cam is ready call reset if (initial1) { camposready = false; zoomready = false; initial1 = false; } CamMode = false; CamTarget = CamOrig; CamZoom = CamOrigZoom; CamScale = 0.1f; CamBound = 0.02f; FuelUi.SetTrigger(animIDreset); //trigger reset animation FuelUi.ResetTrigger(animID); //fade out fuel bar Fuelrect = FuelBar.GetComponent<Image>(); Color fade = Fuelrect.color; fade.a = fade.a - 0.1f; Fuelrect.color = fade; //fade in launch button LaunchImage = Launch.GetComponent<Image>(); Color fadebeta = LaunchImage.color; fadebeta.a = fadebeta.a + 0.1f; if (fadeininitial) { fadebeta.a = -3f; fadeininitial = false; } LaunchImage.color = fadebeta; if (camposready && zoomready) { ResetControl(); } } else if (GameStatus == 8) { //menus CamMode = true; //prevent dynacam doing weird stuff } else { //out of bounds Debug.LogError("Invalid GameStatus"); } if (CamMode==false){ //DynaCamprotections if (CamTarget==Vector3.zero){ CamTarget=CamOrig; } if (CamZoom==0f){ CamZoom=CamOrigZoom; } //call the glorious DynaCam DynaCam(CamTarget,CamZoom,CamScale,CamBound,Revoke); } if (GameStatus!=6f){ time=time+1*Time.deltaTime; } if (GameStatus != GamestatusStore) { Debug.LogWarning("GameStatus now " + GameStatus); GamestatusStore = GameStatus; } //Cam collider pointer //can functionalise and increase for multiple indicators if (inLevel&&indicatorneeded){ boxcoll.size=new Vector2((4f*Camupdate.orthographicSize)-3f,(2f*Camupdate.orthographicSize)-2f); //need to possibly change values here RaycastHit2D hit=Physics2D.Linecast(Earth.transform.position,MainCamupdate.transform.position,Physics2D.DefaultRaycastLayers,-Mathf.Infinity,-9); if (hit.rigidbody!=null){ Vector3 indicatorv3=new Vector3 (hit.point.x,hit.point.y,-2); Indicator.transform.localScale=new Vector3(Camupdate.orthographicSize*0.02f,Camupdate.orthographicSize*0.02f,1f);//unsure of the value best suited here, but this code is ready for graphics pass Indicator.transform.position=indicatorv3; } } //Fuel bar percentage code //fuel = fuel - 1 * Time.deltaTime; //test line if (inLevel){ FuelBar = GameObject.Find("fuel"); fuelbartransform = FuelBar.GetComponent<RectTransform>(); Debug.Log("FUEL " + fuel); if (fuel > 0) fuelbartransform.localScale = new Vector3(fuel / DataPlay.InitialFuel[Application.loadedLevel], 1f, 1f); else fuelbartransform.localScale = Vector3.zero; } if (fuelloading) { fuel = Mathf.Lerp(fuel,DataPlay.InitialFuel[Application.loadedLevel], 0.05f); } //DynaMove activation if (moveInaction) { dynaMove(inputTransform, DynaMoveTarget, dynaMoveBound); } //fuel button fade //fade in fuel button if (fadeneeded) { LaunchImage = Launch.GetComponent<Image>(); Color fadebeta = LaunchImage.color; fadebeta.a = fadebeta.a + fadevalue; LaunchImage.color = fadebeta; } //Camera clamping for boundaries Camupdate.transform.position = new Vector3(Mathf.Clamp(Camupdate.transform.position.x, DataPlay.xboundsx[Application.loadedLevel], DataPlay.xboundsy[Application.loadedLevel]), Mathf.Clamp(Camupdate.transform.position.y, DataPlay.yboundsx[Application.loadedLevel], DataPlay.yboundsy[Application.loadedLevel]), -10f); }
private void Awake() { Instance = this; }