void Update() { if (!isDead && !win) { gameTimer -= Time.deltaTime; score += scoreGained; if (ship.transform.position.y >= minY && ship.transform.position.y <= maxY) { cam.transform.position = new Vector3(cam.transform.position.x, ship.transform.position.y, camPosZ); } if (ship.transform.position.x >= minX && ship.transform.position.x <= maxX) { cam.transform.position = new Vector3(ship.transform.position.x, cam.transform.position.y, camPosZ); } else if (ship.transform.position.x <= minX) { cam.transform.position = new Vector3(minX, cam.transform.position.y, camPosZ); } else if (ship.transform.position.x >= maxX) { cam.transform.position = new Vector3(maxX, cam.transform.position.y, camPosZ); } if (ship.onGround) { scoreGained = 0; } else if (ship.flying) { scoreGained = 0.5f; } else if (ship.floating) { scoreGained = 1.0f; } } scoreText.text = "Score: " + score.ToString("F2"); timerText.text = "Timer: " + gameTimer.ToString("F2"); if (ship.HasPlayerLanded()) { scoreText.gameObject.SetActive(false); timerText.gameObject.SetActive(false); if (!win) { score += winBonus; } win = true; } if (gameTimer <= 0) { ship.DestroyShip(); } if (ship) { distancePlayerPlatform = Vector2.Distance(ship.transform.position, platform.transform.position); if (distancePlayerPlatform < 25 && camPosZ < -50) { camPosZ += offset; } else if (distancePlayerPlatform > 25 && camPosZ > -100) { camPosZ -= offset; } } }
void OnCollisionEnter2D(Collision2D col) { ship.DestroyShip(); }