Professional Documents
Culture Documents
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
void Start()
{
rb2d = GetComponent<Rigidbody2D>();
count = 0;
health = 3;
winText.text = "";
loseText.text = "";
restartText.text = "";
gameOverText.text = "";
nextLevelText.text = "";
SetCountText();
SetHealthText();
gameOver = false;
nextLevel = false;
restart = false;
}
void Update()
{
if(Input.GetKey("escape"))
{
Application.Quit();
}
if(restart)
{
if(Input.GetKeyDown(KeyCode.R))
{
SceneManager.LoadScene("Level 1 - Sunny Day");
}
if(nextLevel)
{
if(Input.GetKeyDown(KeyCode.L))
{
SceneManager.LoadScene("Level 2 - Cloudy Day");
}
}
}
}
}
void SetCountText()
{
countText.text = "Cookies: " + count.ToString();
if (count >= 5)
{
winText.text = "Level Complete!";
FindObjectOfType<SoundEffects>().WinMusic();
GameOver();
if (gameOver)
{
nextLevelText.text = "Press 'L' for Next Level";
nextLevel = true;
speed = 0;
jumpForce = 0;
jumpForce1 = 0;
}
}
}
void SetHealthText()
{
healthText.text = "Lives: " + health.ToString();
if(health == 0)
{
loseText.text = "You Lose!";
GameOver();
if (gameOver)
{
restartText.text = "Press 'R' for Level Restart";
restart = true;
speed = 0;
jumpForce = 0;
jumpForce1 = 0;
}
}
}
gameOver = true;
}
}