public void TogglePause() { var paused = !GlobalGame.Get().currentLevel.GetPause(); GlobalGame.Get().currentLevel.SetPause(paused); pauseMenu.SetActive(paused); }
void OnTriggerEnter2D(Collider2D other) { if (other.gameObject.tag == "Player") { GlobalGame.Get().currentLevel.PlayerWin(); } }
void Update() { var level = GlobalGame.Get().currentLevel; if (level.IsPlayable()) { level.timeSpent += Time.deltaTime; textComponent.text = Mathf.RoundToInt(level.timeSpent).ToString(); } }
void OnTriggerEnter2D(Collider2D other) { if (other.gameObject.tag == "Player") { var contact = other.bounds.ClosestPoint(transform.position); Instantiate(explosion, contact, Quaternion.identity); GlobalGame.Get().currentLevel.PlayerDie(); Destroy(other.gameObject); } }
public void PlayerWin() { player.GetComponent <Rigidbody2D> ().velocity = Vector2.zero; // Fix the position of the player on finish. player.GetComponent <Rigidbody2D> ().bodyType = RigidbodyType2D.Static; playerInteractive = false; pauseButton.SetActive(false); winMenu.SetActive(true); // No next level for last level. continueButton.SetActive(GlobalGame.Get().levelIndex != GlobalGame.levels.Length - 1); }
void FixedUpdate() { if (GlobalGame.Get().currentLevel.IsPlayable() && player != null) { var desired = player.transform.position + offset; var halfHeight = GetComponent <Camera> ().orthographicSize; var halfWidth = halfHeight / Screen.height * Screen.width; desired.x = Mathf.Min(topRight.x + border - halfWidth, Mathf.Max(bottomLeft.x - border + halfWidth, desired.x)); desired.y = Mathf.Min(topRight.y + border - halfHeight, Mathf.Max(bottomLeft.y - border + halfHeight, desired.y)); transform.position = Vector3.SmoothDamp(transform.position, desired, ref velocity, smoothTime); } }
void SetDeathAndLevelPanel() { GameObject.Find("Death Value").GetComponent <Text> ().text = GlobalGame.Get().totalDeath.ToString(); GameObject.Find("Level Value").GetComponent <Text> ().text = (GlobalGame.Get().levelIndex + 1).ToString(); }
public void RestartLevel() { ++GlobalGame.Get().totalDeath; SceneManager.LoadScene(SceneManager.GetActiveScene().name); }
public void LoadNextLevel() { SceneManager.LoadScene(GlobalGame.levels [++GlobalGame.Get().levelIndex]); }
void Awake() { GlobalGame.Get().currentLevel = this; }
void Start() { pauseMenu = GameObject.Find("Menus").transform.Find("Pause Menu").gameObject; GlobalGame.Get().currentLevel.SetPause(false); }
void Update() { if (Input.GetMouseButtonDown(0)) { if (EventSystem.current.IsPointerOverGameObject() || EventSystem.current.IsPointerOverGameObject(0) || !GlobalGame.Get().currentLevel.IsPlayable()) { return; } var mousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition); mousePosition.z = 0; var hits = Physics2D.OverlapPointAll(mousePosition); foreach (var hit in hits) { if (hit.gameObject.tag == "Planet") { Destroy(hit.transform.parent.gameObject); Instantiate(explosion, mousePosition, Quaternion.identity); var blasts = Physics2D.OverlapCircleAll(hit.transform.position, blastRadius); foreach (var blast in blasts) { if (blast.gameObject.tag == "Player") { var direction = blast.transform.position - hit.transform.position; direction.Normalize(); blast.GetComponent <Rigidbody2D> ().AddForce(blastImpulse * direction, ForceMode2D.Impulse); break; } } return; } } hits = Physics2D.OverlapCircleAll(mousePosition, overlapRadius); foreach (var hit in hits) { if (hit.gameObject.tag == "Planet" || hit.gameObject.tag == "Meteroid") { return; } } var newPlanet = Instantiate(planets [Random.Range(0, planets.Length)], (Vector2)mousePosition, Quaternion.identity); iTween.ScaleFrom(newPlanet, iTween.Hash("scale", new Vector3(0.1f, 0.1f, 1f), "time", 0.3f)); } }