i created weapon class which is the parent class,and it has 2 childs “gun subclass” and “MachinGun sub class” my aim,is how to switch betweel class ,have i to use list and displaying in UI ? or i workd IEnumerator to switch between them ? am kind stuck here rlyhere is my code
using UnityEngine;
using System.Collections;
public class Inherit : MonoBehaviour {
public int Damage;
public int Ammo;
public int health;
public string[] _NameWep;
public float _TimeBetwenShots;
public int _BulletSpeed;
public float _ShotCounter;
public GameObject Bullet_G;
//public GameObject _BulletF;
public Transform _FirePoint;
//public int numSelectors = 5;
void Update()
{
Firing ();
}
public virtual void Firing()
{ //Bullet_G = new GameObject[numSelectors];
if (Input.GetButton ("Fire1"))
{
_ShotCounter -= Time.deltaTime;
if (_ShotCounter <= 0) {
_ShotCounter = _TimeBetwenShots;
//for(int i = 0; i < numSelectors; i++)
//{
GameObject bulletObj = Instantiate (Bullet_G, _FirePoint.position, _FirePoint.rotation) as GameObject;
//Bullet_G [numSelectors] = bulletObj;
bulletObj.GetComponent<Rigidbody2D> ().velocity = transform.right * _BulletSpeed;
} else
{_ShotCounter = 0;
}
}
}
public class gun : Inherit
{
void Update()
{
Firing(); // i called Firing function in gun subclass to shoot bullets
}
}
public class MachinGun : Inherit
{
void Start () {
}
// Update is called once per frame
void Update () {
}
}
}