private void Update() { //FPS target if (settings.targetFPS != Application.targetFrameRate) { Application.targetFrameRate = settings.targetFPS; } //Unlock cursor if game not focused if (!Application.isFocused) { Cursor.lockState = CursorLockMode.None; } //Screenshot if (binds.GetInputDown(binds.bindSaveScreenshot)) { SaveScreenshot(); } //Origin looping (maybe this could go in LateUpdate() to avoid the UI shaking) if (generation.instancePlayer.transform.Find("Body").position.magnitude > ORIGIN_LOOP_RADIUS) { LoopWorldOrigin(); } //Map camera follows player generation.instancePlayer.transform.Find("Position Mount").Find("Map Camera").position -= new Vector3( generation.instancePlayer.transform.Find("Body").position.x, 0f, generation.instancePlayer.transform.Find("Body").position.z ); }
private void SetWaypointUI(RaycastHit hit) { renderWaypoint = true; Vector3 waypointWorldPos = hit.collider.transform.position; Vector2 waypointUIPos = Camera.main.WorldToScreenPoint(waypointWorldPos); waypointUIPos.x = Mathf.Clamp(waypointUIPos.x, waypointXMin, waypointXMax); waypointUIPos.y = Mathf.Clamp(waypointUIPos.y, waypointYMin, waypointYMax); waypointImage.transform.position = waypointUIPos; //Check if position is behind camera if (Vector3.Dot(waypointWorldPos - Camera.main.transform.position, Camera.main.transform.forward) < 0f) { if (waypointUIPos.x < Screen.width / 2f) { waypointUIPos.x = waypointXMax; } else { waypointUIPos.x = waypointXMin; } if (waypointUIPos.y < Screen.height / 2f) { waypointUIPos.y = waypointYMax; } else { waypointUIPos.y = waypointYMin; } } waypointTextType.transform.position = new Vector2(waypointUIPos.x + WAYPOINT_X_OFFSET, waypointUIPos.y + WAYPOINT_Y_OFFSET + waypointTextBody.fontSize + waypointTextTitle.fontSize + waypointTextType.fontSize); waypointTextTitle.transform.position = new Vector2(waypointUIPos.x + WAYPOINT_X_OFFSET, waypointUIPos.y + WAYPOINT_Y_OFFSET + waypointTextBody.fontSize + waypointTextTitle.fontSize); waypointTextBody.transform.position = new Vector2(waypointUIPos.x + WAYPOINT_X_OFFSET, waypointUIPos.y + WAYPOINT_Y_OFFSET + waypointTextBody.fontSize); //Set as target too if LMB if (binds.GetInputDown(binds.bindSetTarget)) { //Target SetPlayerTargetObject(hit.collider.transform.gameObject); //Console TextMesh consoleTargetTypeAndTitleText = control.generation.instancePlayer.transform.Find("Body").Find("FP Model").Find("Interior").Find("Display Strut Left").Find("Target Type And Title Text").GetComponent <TextMesh>(); targetTypeAndTitle = waypointTextType.text + "\n" + waypointTextTitle.text; consoleTargetTypeAndTitleText.text = targetTypeAndTitle; } }
private void Update() { //DEBUG //--------------------------------------------------- //Free money if (binds.GetInputDown(binds.bindCheat1)) { currency += 1000; control.ui.UpdateAllPlayerResourcesUI(); control.ui.SetTip("Show me the money."); } //Add ore water /* * if (binds.GetInputDown(binds.bindThrustVectorDecrease)) * { * ore[ORE_WATER] += 1.0; * control.ui.UpdateAllPlayerResourcesUI(); * } */ //Teleport forward /* * if (binds.GetInputDown(binds.bindThrustVectorIncrease)) * { * transform.position += transform.forward * 1e4f; * Debug.Log("Teleported forward: distance to star " + (control.generation.instanceCentreStar.transform.position - transform.position).magnitude); * } */ //Spawn if (binds.GetInputDown(binds.bindCheat2)) { control.generation.SpawnAsteroidManually( transform.position + transform.forward * 3f, rb.velocity, CBodyAsteroid.GetRandomSize(), CBodyAsteroid.GetRandomType(), CBodyAsteroid.HEALTH_MAX ); control.ui.SetTip("Spawned one asteroid."); upgradeLevels[control.commerce.UPGRADE_SEISMIC_CHARGES] = 1; control.ui.SetTip("Seismic charges unlocked."); } /* * if (binds.GetInputDown(binds.bindThrustVectorDecrease)) * { * control.SpawnPlanetoidManually(transform.position + transform.forward * 20f, rb.velocity, null); * Debug.Log("Spawned one planetoid"); * } */ //Slow motion /* * if (binds.GetInput(binds.bindPrimaryFire)) * { * Time.timeScale = 0.01f; * } * else if (!Menu.menuOpenAndGamePaused) * { * Time.timeScale = 1f; * } */ //--------------------------------------------------- //Slow update if (Time.frameCount % 3 == 0) { SlowUpdate(); } //Have the position mount follow the player position positionMount.transform.position = transform.position; //Setup the camera if (!fovSet) { SetCameraSettings(); } //AUDIO UpdateAudio(); //Don't run if paused if (!Menu.menuOpenAndGamePaused) { UpdateGetIfMoving(); //Check if moving at all so that it only has to be checked once per update UpdatePlayerWeapons(); //Shoot stuff UpdatePlayerEngineEffect(); //Set engine glow relative to movement //Fuel decrement if (canAndIsMoving) { vitalsFuel = Math.Max(0.0, vitalsFuel - ((vitalsFuelConsumptionRate / (1 + upgradeLevels[control.commerce.UPGRADE_FUEL_EFFICIENCY])) * Time.deltaTime)); } //Fuel increment (in-situ refinery) bool missingEnoughFuel = vitalsFuel < vitalsFuelMax - REFINERY_FUEL_OUT_RATE; bool hasUpgrade = upgradeLevels[control.commerce.UPGRADE_IN_SITU_FUEL_REFINERY] >= 1; bool hasEnoughOre = ore[ORE_WATER] > REFINERY_ORE_WATER_IN_RATE; bool enoughTimeHasPassed = Time.time > refineryTimeAtLastRefine + REFINERY_TIME_BETWEEN_REFINES; if (missingEnoughFuel && hasUpgrade && hasEnoughOre && enoughTimeHasPassed && control.settings.refine) { ore[ORE_WATER] -= REFINERY_ORE_WATER_IN_RATE; vitalsFuel += REFINERY_FUEL_OUT_RATE; control.ui.UpdatePlayerOreWaterText(); refineryTimeAtLastRefine = Time.time; } //Warn on loop if out of fuel if (vitalsFuel <= 0d && warningUIFlashTime <= 0f) { FlashWarning("Fuel reserves empty"); //Loop smoothly and indefinitely warningUIFlashTime = warningUIFlashTotalDuration * 100f; } //Without this it would be possible for the out of fuel warning to flash indefinitely if you ran out of fuel right as you entered a station if (vitalsFuel > 0d && warningUIText.text == "Fuel reserves empty") { warningUIFlashTime = 0f; warningUIFlashPosition = 1f; } //Update map player ship position transform.parent.Find("Ship Map Model").position = transform.position; /* * transform.parent.Find("Ship Map Model").position.Set( * transform.position.x, * 1000f, * transform.position.z * ); */ } }