嗨我正在为我的自上而下制作一个武器系统mmo并且在我上一个问题的帮助之后我设法让它工作但它需要很多编码来添加ID中的新武器,就像我帮助我如何缩短这个过程一样
using UnityEngine;
using System.Collections;
namespace States
{
public enum PlayerState{Forward,Backward,Left,Right}
public enum CurrentWeapon{Sword,Bow}
}
using UnityEngine;
using System.Collections;
using States;
[System.Serializable]
public class Weapons {// class for weapon variables
public GameObject WeaponFront;
public GameObject WeaponBack;
public GameObject WeaponLeft;
public GameObject WeaponRight;
public float Damage;
}
public class WeaponHandler : MonoBehaviour
{
public States.CurrentWeapon Weapon;
public Weapons Sword = new Weapons();//creating new weapons
public Weapons Bow = new Weapons();
Weapon weaponScript;
void Start()
{
weaponScript = GetComponent<Weapon> ();//accesing the attacking script
}
void Update()
{
if (Weapon == CurrentWeapon.Sword){//all of this code is requried to set up 1 weapon
Sword.WeaponFront.SetActive(true);//which is quite alot would ther be an easier way
Sword.WeaponBack.SetActive(true);
Sword.WeaponLeft.SetActive(true);
Sword.WeaponRight.SetActive(true);
weaponScript.Damage = Sword.Damage;
}
else{
Sword.WeaponFront.SetActive(false);
Sword.WeaponBack.SetActive(false);
Sword.WeaponLeft.SetActive(false);
Sword.WeaponRight.SetActive(false);
}
}
}