Skip to content
Permalink
Browse files
Add files via upload
  • Loading branch information
luoq10 committed Apr 30, 2021
0 parents commit e4b1e1f2f3b9b92d8e05265f0a9dab68501ca95d
Show file tree
Hide file tree
Showing 14 changed files with 1,810 additions and 0 deletions.
@@ -0,0 +1,23 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class FX_Destroy : MonoBehaviour
{

public float m_timer = 1.0f;

// Start is called before the first frame update
void Start()
{

Destroy(this.gameObject, m_timer);//Automatic destruction after 1s

}

// Update is called once per frame
void Update()
{

}
}
@@ -0,0 +1,135 @@
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;

[AddComponentMenu("Game/GameManager")]
public class GameManager : MonoBehaviour
{

public static GameManager Instance = null;
public static int _ammo = 1;//Type of bullets
//Number of pistol bullets
public static int n_ammo = 30;
//Number of machine gun bullets
public static int m_ammo = 100;

public Text txt_ammo01; //Pistol ammunition text
public Text txt_ammo02; //Machine gun ammunition text

public GameObject ShezhiPanel; //Settings panel

public Button GameAgainPlayButton; //Game restart button
public Button GameRePlayButton; //Game continue button
public Button GameQuitButton; //Game quit button
public static bool MoveController = false;//Pause or not


Player m_player;

public int Level_num = 3;

// Use this for initialization
void Start()
{
MoveController = false;
Instance = this;
GameAgainPlayButton.onClick.AddListener(GameAgainPlayButtonListener); //Add game restart button listener
GameRePlayButton.onClick.AddListener(GameRePlayButtonClickListener); //Add game continue button listener
GameQuitButton.onClick.AddListener(GameQuitButtonClickListener); //Add game quit button listener

//Get the player
m_player = GameObject.FindGameObjectWithTag("Player").GetComponent<Player>();
}

void Update()
{
if (Input.GetKeyDown(KeyCode.O))
{
StopButtonClickListener();
}
}

// Update ammunition
public void SetAmmo(int ammo)
{
if (_ammo == 1)
{
m_ammo -= ammo;
txt_ammo02.text = m_ammo.ToString() ;
}
else
{
n_ammo -= ammo;
txt_ammo01.text = n_ammo.ToString() ;
}
}

//Reload ammunition
public void AddAmmo()
{
if (_ammo == 1)
{
m_ammo = 100;
txt_ammo02.text = m_ammo.ToString() ;
}
else
{
n_ammo = 30;
txt_ammo01.text = n_ammo.ToString() ;
}
}

//Switch gun
public void ReAmmo()
{
if (_ammo == 1)
{
txt_ammo02.text = m_ammo.ToString() ;
}
else
{
txt_ammo01.text = n_ammo.ToString() ;
}
}

void StopButtonClickListener()
{
GameManager.MoveController = true;//Pause movement

//Unlock mouse cursor
Cursor.lockState = CursorLockMode.None;
Cursor.visible = true;

ShezhiPanel.SetActive(true);//Show pause panel
Time.timeScale = 0;//Game pause
}

void GameAgainPlayButtonListener()
{
n_ammo = 30;//Number of pistol bullets
m_ammo = 100;//Number of machine gun bullets

SceneManager.LoadScene(Level_num);//Restart
Time.timeScale = 1;//resume the game
}

void GameRePlayButtonClickListener()
{
n_ammo = 30;
m_ammo = 100;

GameManager.MoveController = false;
Cursor.lockState = CursorLockMode.Locked;//Lock mouse cursor

ShezhiPanel.SetActive(false);//Close pause panel

Time.timeScale = 1;
}

void GameQuitButtonClickListener()
{
SceneManager.LoadScene(2);
Time.timeScale = 1;
}

}

0 comments on commit e4b1e1f

Please sign in to comment.