Exemple #1
0
    protected override void Start()
    {
        base.Start();

        if (!profile)
        {
            profile = new GunProfile();
        }

        m_fireForce      = profile.firingForce;
        m_fireRate       = profile.firingRate;
        m_fireMode       = profile.firingMode;
        m_burstSize      = profile.burstSize;
        m_magazineSize   = profile.magazineSize;
        m_reloadClipSize = profile.reloadClipSize;
        m_warmUpTime     = profile.warmUpTime;
        m_overheatTime   = profile.overheatTime;
        m_cooldownTime   = profile.cooldownTime;

        shotsRemaining = m_magazineSize;
        burstCount     = 0;
        FiredCount     = 0;

        warmUpTimer   = 0;
        overheatTimer = 0;
        cooldownTimer = 0;

        if (OnBulletFired == null)
        {
            OnBulletFired = new UnityEvent();
        }

        if (OnMagazineEmpty == null)
        {
            OnMagazineEmpty = new UnityEvent();
        }

        if (OnReload == null)
        {
            OnReload = new UnityEvent();
        }

        if (OnBurstStart == null)
        {
            OnBurstStart = new UnityEvent();
        }

        if (OnBurstDone == null)
        {
            OnBurstDone = new UnityEvent();
        }

        OnProjectileSpawned.AddListener(FireBullet);
        OnProjectileRaycast.AddListener(RaycastBullet);
    }
    public void Fire(Vector3 position, Quaternion rotation)
    {
        for (int i = 0; i < Amount; i++)
        {
            Vector3 deviation = new Vector3(UnityEngine.Random.Range(-Deviation, Deviation), UnityEngine.Random.Range(-Deviation, Deviation));
            Vector3 direction = rotation * new Vector3(Mathf.Sin(Mathf.Deg2Rad * deviation.x), Mathf.Sin(Mathf.Deg2Rad * deviation.y), 1);

            GameObject obj        = Instantiate(Projectile, position, rotation);
            Projectile projectile = obj.GetComponent <Projectile>();

            projectile.Direction = direction;
            projectile.Speed     = Speed;
            projectile.Damage    = Damage;

            OnProjectileSpawned?.Invoke(obj);
        }
    }