void InitReferences() { _playerRef = GameObject.FindGameObjectWithTag("Player").GetComponent <Player>(); _cameraRef = GameObject.FindGameObjectWithTag("MainCamera").GetComponent <Camera>(); _parallaxRef = GameObject.Find("Ground").GetComponent <Parallax>(); _gameplayCanvasRef = GameObject.Find("Canvas").GetComponent <GameplayCanvas>(); }
public void PlayButtonClick() { MenuCanvas.GetComponent <Canvas>().enabled = false; GameplayCanvas.GetComponent <Canvas>().enabled = true; transform.position = new Vector3(0, 0, -1); GetComponent <PolygonCollider2D>().enabled = true; GetComponent <Rigidbody2D>().gravityScale = 2.8f; ObstacleGenerator.transform.position = new Vector2(5, 0); score = 0; Score.GetComponent <Text>().text = score.ToString(); }
/// <summary> ///Enter GAMEPLAY State and show READY Text for notifying to the player game will start soon. /// </summary> public void StartGame() { gameState = GameState.GAMEPLAY; MainMemuCanvas.SetActive(false); ReadyText.SetActive(true); GameplayCanvas.SetActive(true); score = 0; scoreText.text = "0"; hightScoreText.text = hightScore.ToString(); liveCount = startLives; livesDisplay.IncreasLive(liveCount); //display amount of player's lives on screen Invoke("StartGamePlay", waitTime); //start game in waitTime secondes }
/// <summary> ///Show gameover scence /// </summary> public void ShowGameOverCanvas() { if (score > hightScore) { SaveHightScore(score); hightScore = score; } gameState = GameState.GAMEOVER; GameplayCanvas.SetActive(false); GameOverText.SetActive(false); GameOverCanvas.SetActive(true); GOVscoreText.text = score.ToString(); }
void OnCollisionEnter2D(Collision2D other) { if (PlayerPrefs.GetInt("HighScore") < score) { PlayerPrefs.SetInt("HighScore", score); } GetComponent <PolygonCollider2D>().enabled = false; GetComponent <Rigidbody2D>().gravityScale = 0; ObstacleGenerator.transform.position = new Vector2(-5, 0); HighScore.GetComponent <Text>().text = "High Score: " + PlayerPrefs.GetInt("HighScore"); MenuCanvas.GetComponent <Canvas>().enabled = true; GameplayCanvas.GetComponent <Canvas>().enabled = false; transform.position = new Vector3(transform.position.x, transform.position.y, 10); GameObject exp = Instantiate(Explosion, new Vector2(transform.position.x, transform.position.y), Quaternion.identity) as GameObject; Destroy(exp, 0.58f); }