【发布时间】:2018-11-16 23:52:12
【问题描述】:
我正在尝试统一构建一个 FPS 游戏,并且我正在尝试通过一个角色来实现武器装备。 为此,我有:
- 公共抽象武器类
- 一个继承自 Weapon.cs 的 MachineGun 类
- 一个角色类,配备一系列武器
武器类:
public abstract class Weapon : MonoBehaviour {
lots of weapon code
}
机关枪类:
public class MachineGun : Weapon{
lots of machinegun code
}
在 Character 类中,我这样做:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
//keeps track of all the character properties
public class Character : MonoBehaviour {
public GameObject[] _equipedWeapons = new GameObject[10]; //an array of all the weapons a character has
private void Start()
{
_equipedWeapons = new GameObject[10]; //size of the weapons array, TEMP 10
_equipedWeapons[0] = new GameObject();
_equipedWeapons[0] = GameObject.FindWithTag("Weapon0");
}
这就是我的问题所在:
public void IncreaseBullets(int amount)
{
_equipedWeapons[0].;
}
我似乎无法了解这把机关枪的子弹数量。 事实上,我无法访问它自己的机枪字段或继承的武器字段。
【问题讨论】:
标签: c# arrays unity3d field abstract-class