Example #1
0
    public bool PrimaryFire(WeaponWielder firer, bool tryAuto)
    {
        if (tryAuto && cooldownClock >= shotCooldownTime && !reloading)
        {
            if (curAmmo == 0)
            {
                Reload(firer);
                return(false);
            }

            float spreadLinearMax = Mathf.Sin(Mathf.Deg2Rad * (spreadAngle / 2));

            float   spreadLinear = Random.Range(0, spreadLinearMax);
            Vector3 fireVec      = Quaternion.AngleAxis(Random.Range(0, 360), transform.forward) * (transform.forward + (transform.up * spreadLinear));

            GameObject projectile = GameObject.Instantiate(projectilePrefab);
            Projectile proj       = projectile.GetComponent <Projectile>();
            if (proj == null)
            {
                Debug.LogError("Tried to shoot not a projectile");
            }

            projectile.transform.position = transform.position + transform.forward;
            proj.direction = fireVec;

            curAmmo--;
            cooldownClock = 0;

            return(true);
        }
        else
        {
            return(false);
        }
    }
Example #2
0
    public bool PrimaryFire(WeaponWielder firer, bool tryAuto)
    {
        if (!tryAuto)
        {
            if (curAmmo == 0)
            {
                Reload(firer);
                return(false);
            }

            GameObject projectile = GameObject.Instantiate(projectilePrefab);
            Projectile proj       = projectile.GetComponent <Projectile>();
            if (proj == null)
            {
                Debug.LogError("Tried to shoot not a projectile");
            }

            projectile.transform.position = transform.position + transform.forward;
            proj.direction = transform.forward;

            curAmmo--;

            return(true);
        }
        else
        {
            return(false);
        }
    }
Example #3
0
    public bool Reload(WeaponWielder firer)
    {
        if (curAmmo == maxAmmo)
        {
            return(false);
        }

        Debug.Log("Reloading...");
        curAmmo = maxAmmo;
        return(true);
    }
Example #4
0
    private void Start()
    {
        wielder  = GetComponent <WeaponWielder>();
        reloadUI = GameObject.Find("ReloadIndicator").GetComponent <ProgressBar>();

        curWeaponIndex = 0;
        ChangeToWeapon(curWeaponIndex);

        wielder.onWeaponReloadEvent.AddListener(OnWeaponReload);

        headTransform = GetComponentInChildren <Camera>().transform;
    }
Example #5
0
    public bool Reload(WeaponWielder firer)
    {
        if (curAmmo == maxAmmo || reloading)
        {
            return(false);
        }

        reloading     = true;
        cooldownClock = 0;

        Debug.Log("Reloading...");
        curAmmo = maxAmmo;
        return(true);
    }
Example #6
0
 public bool PrimaryFire(WeaponWielder firerer, bool tryAuto)
 {
     if (!tryAuto)
     {
         Debug.Log("Bang!");
         GameObject ball = GameObject.CreatePrimitive(PrimitiveType.Sphere);
         ball.transform.position = transform.position;
         Destroy(ball, 4);
         return(true);
     }
     else
     {
         return(false);
     }
 }
Example #7
0
 public bool Reload(WeaponWielder firerer)
 {
     return(false);
 }
Example #8
0
 public bool PrimaryFire(WeaponWielder firerer, bool tryAuto)
 {
     return(false);
 }