123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158 |
-
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.SceneManagement;
- public class Nexus : MonoBehaviour {
- static Nexus currentInstance;
- public int maxHealth = 1000;
- public int maxMana = 1000;
- public float manaRegenRate = 1.0f;
- int currentHealth;
- int currentMana;
- int manaSpent = 0;
-
- MeshRenderer mRen;
-
- public GameObject explosionPrefab;
-
-
-
- public int CurrentHealth
- {
- get { return currentHealth; }
- }
-
-
-
- public float CurrentHealthPercent
- {
- get { return (float)currentHealth / (float)maxHealth; }
- }
-
-
-
- public int CurrentMana
- {
- get { return currentMana; }
- }
-
-
-
- public float CurrentManaPercent
- {
- get { return (float)currentMana / (float)maxMana; }
- }
-
-
-
- public bool IsDead
- {
- get { return currentHealth <= 0; }
- }
-
-
-
- public static Nexus CurrentInstance
- {
- get { return currentInstance; }
- }
-
- void Awake () {
- currentHealth = maxHealth;
- currentMana = 200;
- currentInstance = this;
- mRen = GetComponent<MeshRenderer>();
- explosionPrefab.SetActive(false);
- }
- public void GoToTitle()
- {
- SceneManager.LoadScene(0);
- }
-
- void Update () {
-
-
-
-
-
-
- if (Input.GetKey(KeyCode.Alpha1)) Time.timeScale = 5;
- else Time.timeScale = 1;
-
- if (IsDead)
- {
- Time.timeScale = 0;
- if (Input.GetKeyDown(KeyCode.Space))
- SceneManager.LoadScene(0);
- }
- }
-
-
-
-
- public void Damage(int power)
- {
- bool alreadyDead = IsDead;
- currentHealth -= power;
- if (IsDead && !alreadyDead) Death();
- }
-
-
-
-
- public void GainMana(int amount)
- {
- currentMana += amount;
- }
-
-
-
-
-
- public bool UseMana(int amount)
- {
-
- if(amount > currentMana)
- {
- Debug.Log("钱不够!");
- return false;
- }
-
- currentMana -= amount;
-
- manaSpent += amount;
- return true;
- }
-
-
-
- void Death()
- {
- explosionPrefab.SetActive(true);
-
-
- mRen.enabled = false;
- for(int i = 0; i < transform.childCount; i++)
- {
- transform.GetChild(i).gameObject.SetActive(false);
- }
-
- }
- }
|