void ChamberRound()
    {
        if (pauseReChamber)
        {
            return;
        }

        pauseReChamber = true;

        GameObject mag = GetInsertedMag();

        if (mag != null)
        {
            Weapon_Magazine weapon_Magazine = mag.GetComponent <Weapon_Magazine>();
            if (weapon_Magazine != null)
            {
                GameObject round = weapon_Magazine.GetTopBullet();
                if (round != null)
                {
                    Bullet_Controller bullet_Controller = round.GetComponent <Bullet_Controller>();
                    if (bullet_Controller != null)
                    {
                        bullet_Controller.TogglePhysics(false);
                        bullet_Controller.RemoveRigidbody();
                        bullet_Controller.isGrabbable   = false;
                        bullet_Controller.isLoadedInMag = false;
                    }

                    round.transform.parent   = loadPoint.transform;
                    round.transform.position = loadPoint.transform.position;
                    round.transform.rotation = loadPoint.transform.rotation;
                }
            }
        }
    }
Exemplo n.º 2
0
    // Update is called once per frame
    void Update()
    {
        // Checks if player is in radius
        Vector3 offset = player.transform.position - transform.position;
        float sqrLen = offset.sqrMagnitude;


        if (sqrLen < 81)
        {
            // Look at player
            transform.LookAt(player.transform);

            // Fire
            shotCounter -= Time.deltaTime;
            if (shotCounter <= 0)
            {
                shotCounter = timeBetweenShots;
                Bullet_Controller newBullet = Instantiate(bullet, firePoint.position, firePoint.rotation);
                newBullet.speed = bulletSpeed;
            }


        }

        // Destuct when money runs out
        if (enemyMoney <= 0)
        {
            Object.Destroy(this.gameObject);
            money.increaseBy(100);
        }

    }
    void Shoot()
    {
        if (weapon.id != 0)
        {
            if (timer < 60 && Time.timeScale != 0)
            {
                timer += Time.deltaTime;
            }

            if (Input.GetButton("Fire1") && Time.timeScale != 0)
            {
                if (weapon.timeBtShoots < timer && Amo > 0)
                {
                    timer = 0;
                    Amo  -= 1;

                    for (int i = 0; i < weapon.multyShoot; i++)
                    {
                        bul = Instantiate(Bullet, firePoint, Quaternion.Euler(0, 0, Torso.transform.eulerAngles.z + Random.Range(weapon.range * -1, weapon.range)));
                        Bullet_Controller b_c = bul.GetComponent <Bullet_Controller>();
                        b_c.Move(Random.Range(50, 70));
                    }
                }
            }
        }
    }
    bool IsRoundUnfired()
    {
        if (!IsChamberEmpty())
        {
            Bullet_Controller bullet_Controller = GetChamberedRound().GetComponent <Bullet_Controller>();
            if (bullet_Controller != null)
            {
                return(!bullet_Controller.hasFired);
            }
        }

        return(false);
    }
Exemplo n.º 5
0
    public void FireWeapon(Vector3 target)
    {
        if (timer >= FireRate)
        {
            timer = 0.0f;
            Bullet_Controller projectile = Instantiate(Bullet, transform.position, Quaternion.identity);
            projectile.tag = tag;
            projectile.GetComponent <Bullet_Controller>().Owner = gameObject;

            Vector2 direction = target - transform.position;
            direction.Normalize();
            projectile.GetComponent <Rigidbody2D>().velocity = direction * BulletSpeed;
        }
    }
Exemplo n.º 6
0
 void OnTriggerEnter(Collider other)
 {
     if (other.tag == "Bullet")
     {
         GameObject bullet = other.gameObject;
         if (bullet != null)
         {
             Bullet_Controller bullet_Controller = bullet.GetComponent <Bullet_Controller>();
             if (bullet_Controller != null && !IsMagazineFull() && !bullet_Controller.isLoadedInMag && !bullet_Controller.hasFired && bullet_Controller.RoundType == compatibleRound)
             {
                 ToggleBulletControl(bullet);
                 AddRound(bullet);
                 bullet_Controller.ForceStopInteracting();
                 bullet_Controller.holdingBullet = false;
             }
         }
     }
 }
    // Update is called once per frame
    void Update()
    {
        //Condition for firing bullets
        if (isFiring)
        {
            shootingCounter -= Time.deltaTime;

            if (shootingCounter <= 0)
            {
                shootingCounter = timeBetweenShots;                 //Reset the shooting of bullets
                Bullet_Controller newBullet = Instantiate(bullet, firePointSpawner.position, firePointSpawner.rotation) as Bullet_Controller;

                newBullet.Speed = bulletSpeed;                 // Set the gameObjects speed
            }
        }
        else
        {
            shootingCounter = 0;             // Set the counter back to zero
        }
    }
    void UnChamberRound()
    {
        GameObject round = GetChamberedRound();

        if (round != null)
        {
            round.transform.parent   = null;
            round.transform.position = casingPoint.transform.position;
            round.transform.rotation = casingPoint.transform.rotation;

            Bullet_Controller bullet_Controller = round.GetComponent <Bullet_Controller>();
            if (bullet_Controller != null)
            {
                bullet_Controller.isGrabbable   = true;
                bullet_Controller.isLoadedInMag = false;
                bullet_Controller.AddRigidbody();
                bullet_Controller.AddForceToBullet(Vector3.right, 100f);
                bullet_Controller.TogglePhysics(true);
            }
        }
    }
Exemplo n.º 9
0
    void ToggleBulletControl(GameObject obj)
    {
        Bullet_Controller bullet_Controller = obj.GetComponent <Bullet_Controller>();

        if (bullet_Controller != null)
        {
            if (obj.GetComponent <Rigidbody>() != null)
            {
                bullet_Controller.TogglePhysics(false);
                bullet_Controller.RemoveRigidbody();
                bullet_Controller.isGrabbable   = false;
                bullet_Controller.isLoadedInMag = true;
            }
            else
            {
                bullet_Controller.TogglePhysics(true);
                bullet_Controller.AddRigidbody();
                bullet_Controller.isGrabbable   = true;
                bullet_Controller.isLoadedInMag = false;
            }
        }
    }
Exemplo n.º 10
0
    void SpawnProjectile()
    {
        GameObject bullet = GetChamberedRound();

        if (bullet != null)
        {
            Bullet_Controller bullet_Controller = bullet.GetComponent <Bullet_Controller>();
            bullet_Controller.hasFired = true;
            bullet_Controller.ToggleBulletVisibility(false);

            GameObject projectile = Instantiate(bullet_Controller.BulletProjectile) as GameObject;
            projectile.transform.position = firePoint.position;
            projectile.transform.rotation = firePoint.rotation;

            Projectile_3 projectile_3 = projectile.GetComponent <Projectile_3>();
            projectile_3.speed               = bullet_Controller.stats.speed;
            projectile_3.damage              = bullet_Controller.stats.damage;
            projectile_3.force               = bullet_Controller.stats.force;
            projectile_3.lifetime            = bullet_Controller.stats.lifetime;
            projectile_3.defaultImpactEffect = bullet_Controller.stats.defaultImpactEffect;

            PlayFireEffects();
        }
    }
Exemplo n.º 11
0
    // Update is called once per frame
    void Update()
    {
        // Instantiate bullets, with cooldown
        if (isFiring)
        {
            shotCounter -= Time.deltaTime;
            if (shotCounter <= 0)
            {
                shotCounter = timeBetweenShots;
                Bullet_Controller newBullet = Instantiate(bullet, firePoint.position, firePoint.rotation);
                newBullet.speed = bulletSpeed;

                money.reduceBy(bulletCost);
            }
        }
        else
        {
            shotCounter -= Time.deltaTime;
            if (shotCounter <= 0)
            {
                shotCounter = 0;
            }
        }
    }
Exemplo n.º 12
0
    private void Start()
    {
        goal = transform.position + new Vector3(Random.insideUnitSphere.x * 5, 0, Random.insideUnitSphere.z * 5);
        mayhemGunshotTimer = Random.Range(0.1f, 1);
        mayhemRotateTimer  = Random.Range(0.1f, 0.5f);

        _uiManager = GameObject.Find("Canvas").GetComponent <UI_Manager>();
        if (_uiManager == null)
        {
            Debug.LogError("The UI Manager is NULL!");
        }

        ammoBag           = GetComponent <AmmoBag>();
        _audioManager     = GameObject.Find("Audio Manager").GetComponent <AudioManager>();
        _bulletController = GetComponent <Bullet_Controller>();
        _playerRb         = GetComponent <Rigidbody>();
        //Instantiate aim target prefab
        if (_targetIndicatorPrefab)
        {
            _targetObject = Instantiate(_targetIndicatorPrefab, Vector3.zero, Quaternion.identity) as GameObject;
        }
        //Hide the cursor
        Cursor.visible = false;
    }
Exemplo n.º 13
0
 // Start is called before the first frame update
 void Start()
 {
     bController = currentProjectile.GetComponent <Bullet_Controller>();
     shootCD     = bController.launchCD;
 }
Exemplo n.º 14
0
 void Start()
 {
     firePoint = GetComponentInChildren <Transform>();
     target    = gameObject.GetComponent <Target>();
     bullet    = gameObject.AddComponent <Bullet_Controller>();
 }