游戏类型的制作

1.文字冒险游戏通过故事卡

2.rpg回合制经验作为一种预制体 ,加载时生成

private bool spawning = false;
  
void Start() {
DontDestroyOnLoad (this.gameObject);
  
SceneManager.sceneLoaded += OnSceneLoaded;
}
  
private void OnSceneLoaded(Scene scene, LoadSceneMode mode) {
if (scene.name == "Battle") {
if (this.spawning) {
Instantiate (enemyEncounterPrefab);
}
SceneManager.sceneLoaded -= OnSceneLoaded;
Destroy (this.gameObject);
}
}
  
void OnTriggerEnter2D(Collider2D other) {
if (other.gameObject.tag == "Player") {
this.spawning = true;
SceneManager.LoadScene ("Battle");
}
}
}

3.健康列表只要角色没死  添加进列表就要sort一下

4.attack目标预制件

5.头顶显示血量也是 UI预制件

6.

public void receiveDamage(float damage) {
this.health -= damage;
animator.Play ("Hit");
  
GameObject HUDCanvas = GameObject.Find ("HUDCanvas");
GameObject damageText = Instantiate (this.damageTextPrefab, HUDCanvas.transform) as GameObject;
damageText.GetComponent<Text> ().text = "" + damage;
damageText.transform.localPosition = this.damageTextPosition;
damageText.transform.localScale = new Vector2 (1.0f, 1.0f);
  
if (this.health <= 0) {
this.dead = true;
this.gameObject.tag = "DeadUnit";
Destroy (this.gameObject);
}
}

7

选择角色单位进行攻击
每个回合都需要正确选择当前的玩家单位,将下面的SelectUnit脚本添加到PlayerParty对象。这个脚本需要引用战斗菜单,所以在加载战斗场景的时候就要对其进行设置。

此外还要实现三种方法:selectCurrentUnit,selectAttack和attackEnemyTarget。 selectCurrentUnit将某个角色单位设置为当前行动单位,启用操作菜单,以便玩家可以选择操作,并更新HUD以显示当前的单位头像,生命值和魔法值。

当前角色单位会在自己的回合调用selectAttack方法,并禁用操作菜单和启用敌人菜单。PlayerUnitAction脚本中也需要实现selectAttack方法。以便玩家在选定攻击方式后选择目标了。

最后,attackEnemyTarget会禁用两个菜单并调用当前单位的act方法,选择敌人作为攻击目标。

8使用下面的脚本来显示单位的生命值和魔法值。该脚本在Start方法中初始化文本最初的localScale。然后在Update方法中根据单位的当前状态值更新localScale。 此外,changeUnit方法用于改变当前正在显示的角色单位,抽象方法newStatValue用于获取当前的状态值。

9

public abstract class ShowUnitStat : MonoBehaviour {
  
[SerializeField]
protected GameObject unit;
  
[SerializeField]
private float maxValue;
  
private Vector2 initialScale;
  
void Start() {
this.initialScale = this.gameObject.transform.localScale;
}
  
void Update() {
if (this.unit) {
float newValue = this.newStatValue ();
float newScale = (this.initialScale.x * newValue) / this.maxValue;
this.gameObject.transform.localScale = new Vector2(newScale, this.initialScale.y);
}
}
  
public void changeUnit(GameObject newUnit) {
this.unit = newUnit;
}
  

10.

请注意,当角色单位死亡后要将其标签更改为“DeadUnit”,

猜你喜欢

转载自www.cnblogs.com/xiaomao21/p/9428876.html