//Getting hit
    void OnTriggerEnter(Collider characterCollider)
    {
        //Checking collision
        if (characterCollider.GetComponent <BulletLogic>() != null)
        {
            BulletLogic bullet = characterCollider.GetComponent <BulletLogic>();

            //Checking if bullet was shot by player
            if (bullet.ShotByPlayer == true)
            {
                bullet.gameObject.SetActive(false);
                health -= bullet.playerBulletDamage;
            }

            //Checking if health if below 0 - if yes then die and respawn ammoPack
            if (health <= 0 && isDead == false)
            {
                bullet.gameObject.SetActive(false);
                isDead = true;
                Destroy(gameObject);
                GameObject ammoPrefab = Instantiate(ammoPack);
                ammoPrefab.transform.position = transform.position + ammoPackVector;
                playerModel.enemiesKilled    += 1;
            }
        }
    }
Ejemplo n.º 2
0
    /// <summary> instantiates the bullet game object variable </summary>
    private void InstantiateBullet()
    {
        GameObject bulletInstance = Instantiate(bulletPrefab, firePoint.position, firePoint.rotation);

        BulletLogic bulletLogic = bulletInstance.GetComponent <BulletLogic>();

        bulletLogic.bulletDamage = (int)rangedAttackDamageToGive.initialValue;         // is this right
    }
Ejemplo n.º 3
0
    public void LaunchProjectile()
    {
        GameObject newBullet = Instantiate(bullet, bulletSpawnPoint.transform.position, bulletSpawnPoint.transform.rotation);

        newBullet.transform.SetParent(transform);
        BulletLogic newBulletLogic = newBullet.GetComponent <BulletLogic>();

        newBulletLogic.Damage      = bulletDamage;
        newBulletLogic.BulletSpeed = bulletSpeed;
    }
Ejemplo n.º 4
0
    // Shoots at the closest enemy
    void Shoot(GameObject enemy)
    {
        bullet                   = (Transform)Instantiate(BulletPrefab, this.transform.position, this.transform.rotation);
        bulletLogicScript        = bullet.GetComponent <BulletLogic> ();
        bulletLogicScript.target = enemy;
        bulletLogicScript.tower  = this.gameObject;

        /*Tower shoot sound*/
        AudioSource.PlayClipAtPoint(TowerShootSound, transform.position);
    }
Ejemplo n.º 5
0
    public override void AltFire(Vector3 mousePos)
    {
        if (ammo >= shotsPerAlt)
        {
            // Mouse position on the screen (In pixels)
            //Vector3 mousePos = Input.mousePosition;

            // Play muzzle flash particle system
            muzzleFlash.Play();

            // Change transparency of this weapon when aiming down the sights
            if (aimDown)
            {
                // Make gun partially transparent
            }
            else
            {
                // Make gun fully opaque
            }

            // Cast a ray from the centre of the viewport, though the camera, into the world
            Ray ray = cam.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0.0f));


            // Shoot the bullet in the same direction as the ray. (slighltly inaccurate, but only used when ray does not hit anything)
            Vector3 bulletDirection = ray.direction;

            // If the ray does hit something, find the direction from the bullet spawn to the point of impact. (Very accurate)
            RaycastHit hit;

            if (Physics.Raycast(ray, out hit))
            {
                bulletDirection = (hit.point - bulletSpawn.position).normalized;
            }

            // Make sure bullet is always facing the way it will shoot towards
            Quaternion bulletRotation = Quaternion.FromToRotation(bullet.transform.forward, bulletDirection);

            /* Spawn a three bullets, along with their necessary information
             * Lose three ammunition.
             */
            for (int i = 0; i < shotsPerAlt; i++)
            {
                //Rigidbody currentBullet = Instantiate(bullet, bulletSpawn.position, bulletRotation);
                GameObject  currentBullet = ObjectPooler.Instance.SpawnObject("Bullet", bulletSpawn.position, bulletRotation);
                BulletLogic bulletLogic   = currentBullet.GetComponent <BulletLogic>();
                bulletLogic.Damage = damage;
                bulletLogic.applyForce(bulletDirection * 4000.0f);
                bulletLogic.OwnerTransform = gameObject.GetComponentInParent <Transform>();
                ammo--;
            }
        }
    }
Ejemplo n.º 6
0
 private void Awake()
 {
     if (instance != null && instance != this)
     {
         Debug.LogError("Ya f****d up A-A-Ron");
         DestroyImmediate(gameObject);
     }
     else
     {
         instance = this;
     }
 }
Ejemplo n.º 7
0
    void Shoot()
    {
        Vector3 bulletSpawn     = transform.position + (transform.forward * 2);
        Vector3 bulletDirection = (enemyManager.player.position - transform.position).normalized;

        GameObject  currentBullet = ObjectPooler.Instance.SpawnObject("Bullet", bulletSpawn, transform.rotation);
        BulletLogic bulletLogic   = currentBullet.GetComponent <BulletLogic>();

        bulletLogic.Damage = 25;
        bulletLogic.applyForce(bulletDirection * 1000.0f);
        bulletLogic.OwnerTransform = gameObject.GetComponentInParent <Transform>();
    }
 //Getting hit by enemy bullet
 void OnTriggerEnter(Collider characterCollider)
 {
     if (characterCollider.GetComponent <BulletLogic>() != null)
     {
         BulletLogic bullet = characterCollider.GetComponent <BulletLogic>();
         if (bullet.ShotByPlayer == false)
         {
             bullet.gameObject.SetActive(false);
             health        -= bullet.enemyBulletDamage;
             timeFromAttack = 0;
         }
     }
 }
Ejemplo n.º 9
0
 // Checks if the array contains a bullet of this type
 public bool Contains(BulletLogic type)
 {
     for (int i = 0; i < Count; i++)
     {
         // If they match then return true
         if (buarray[i].logicType == type)
         {
             return(true);
         }
     }
     // If there wasnt one of that type then
     return(false);
 }
Ejemplo n.º 10
0
    // Update is called once per frame
    void Shoot()
    {
        GameObject Shot = (GameObject)Instantiate(enemyBullet, bulletspawnplace.transform.position, bulletspawnplace.transform.rotation);
        //Here i will adjust the dmg the shot does based on the charge
        Damage      shotdamage = Shot.GetComponent <Damage>();
        BulletLogic shotlogic  = Shot.GetComponent <BulletLogic>();

        shotdamage.damageAmount = dmgBullet;
        shotlogic.m_Speed       = speedBullet;
        canShoot      = false;
        cooldowntimer = cooldownShoot;

        shootingEffect.GetComponent <AudioSource>().Play();
    }
Ejemplo n.º 11
0
    IEnumerator BulletRecall(Transform bullet, Vector3 endPosition)
    {
        float       t             = 0;
        Vector3     startPosition = bullet.position;
        BulletLogic stats         = bullet.GetComponent <BulletLogic>();

        while (t < 1)
        {
            stats.lifetime  = bulletLifetime;
            bullet.position = Vector3.Lerp(startPosition, endPosition, t);
            t += Time.deltaTime;
            yield return(null);
        }
    }
Ejemplo n.º 12
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Space))
        {
            var     bullet       = Instantiate(BulletPrefab);
            Vector2 fireVelocity = GetComponent <PlayerController>().FacingDirection *Vector2.right *BulletSpeed;

            bullet.GetComponent <Rigidbody2D>().velocity = fireVelocity;
            bullet.transform.position = gameObject.transform.position;

            BulletLogic bL = bullet.GetComponent <BulletLogic>();

            if (bL)
            {
                bL.DamageAmount = damage_;
            }
        }
    }
Ejemplo n.º 13
0
    private void ShootChargedShot()
    {
        GameObject Shot = (GameObject)Instantiate(projectile, gunPoint.position, gunPoint.rotation);
        //Here i will adjust the dmg the shot does based on the charge

        Damage      shotdamage = Shot.GetComponent <Damage>();
        BulletLogic shotlogic  = Shot.GetComponent <BulletLogic>();

        shotdamage.damageAmount   = charge * chargeToDamage;
        Shot.transform.localScale = Shot.transform.localScale * (chargeStartScale + charge) * chargeToScaleRation;
        shotlogic.m_Speed         = chargedShotSpeed;

        playerBody.GetComponent <PlayerController>().AddForce(-playerCam.transform.forward * charge * chargeToKnockBackValue); // KnockBaco

        chargingSoundEffect.GetComponent <AudioSource>().Stop();
        shootingSoundEffect.GetComponent <AudioSource>().Play();
        charge = 0f;
    }
Ejemplo n.º 14
0
    void OffScreenShot()
    {
        BulletType type = BulletType.Boomerang;
        Direction  dir  = playerMovement.lastDirection;

        BulletDepot.Volley volley = bullets.types[(int)playerStats.character].projectileTypes[(int)type].volleys[bufferIter];



        for (int i = 0; i < volley.volley.Length; i++)
        {
            BulletDepot.Bullet bullet = volley.volley[i];
            int        angle          = bullet.angle + (int)playerMovement.CurrentShotAngle();
            GameObject newBullet      = bullets.GetBullet();
            switch (dir)
            {
            case Direction.Right:
                newBullet.transform.position = new Vector3(42, -25 + (60 / volley.volley.Length) * i, 0);
                break;

            case Direction.Left:
                newBullet.transform.position = new Vector3(-42, -25 + (60 / volley.volley.Length) * i, 0);
                break;

            case Direction.Down:
                newBullet.transform.position = new Vector3(-42 + (60 / volley.volley.Length) * i, -25, 0);
                break;

            case Direction.Up:
                newBullet.transform.position = new Vector3(-42 + (60 / volley.volley.Length) * i, 25, 0);
                break;
            }

            newBullet.transform.rotation = Quaternion.Euler(0, 0, angle);
            BulletLogic bulletLogic = newBullet.GetComponent <BulletLogic>();           //((GameObject)Instantiate(bulletPrefab, gameObject.transform.position, Quaternion.Euler(0, 0, angle))).GetComponent<BulletLogic>();
            bulletLogic.Initialize(type, bullet.damage, bullet.speed, bullet.size, lifetime, playerStats.playerColor, playerStats.number, playerStats.character);
            bulletLogic.indirectHomingTime      = 10.5f;
            bulletLogic.indirectHomingLimit     = 1.0f;
            bulletLogic.indirectCorrectionSpeed = 1.5f;
            newBullet.GetComponentInChildren <SpriteRenderer>().sortingOrder = 9 - bufferIter;
        }
        soundEffects.clip = Resources.Load <AudioClip>("audio/soundEffects/boomerangSound");
        soundEffects.Play();
    }
Ejemplo n.º 15
0
 void OffScreenFinalShot()
 {
     for (int i = 0; i < 4; i++)
     {
         GameObject newBullet = bullets.GetBullet();
         newBullet.transform.position = new Vector3(-30 + (15 * i), 20, 0);
         newBullet.transform.rotation = Quaternion.Euler(0f, 0f, 270f);
         BulletLogic bulletLogic = newBullet.GetComponent <BulletLogic>();
         // just values I'm making up
         bulletLogic.Initialize(BulletType.Boomerang, 10, 20, 2, 10, playerStats.playerColor, playerStats.number, playerStats.character);
         newBullet.GetComponentInChildren <SpriteRenderer>().sortingOrder = 9 - bufferIter;
     }
     for (int i = 0; i < 4; i++)
     {
         GameObject newBullet = bullets.GetBullet();
         newBullet.transform.position = new Vector3(-30 + (15 * i), -20, 0);
         newBullet.transform.rotation = Quaternion.Euler(0f, 0f, 90f);
         BulletLogic bulletLogic = newBullet.GetComponent <BulletLogic>();
         // just values I'm making up
         bulletLogic.Initialize(BulletType.Boomerang, 10, 20, 2, 10, playerStats.playerColor, playerStats.number, playerStats.character);
         newBullet.GetComponentInChildren <SpriteRenderer>().sortingOrder = 9 - bufferIter;
     }
     for (int i = 0; i < 4; i++)
     {
         GameObject newBullet = bullets.GetBullet();
         newBullet.transform.position = new Vector3(-35, -15 + (i * 8), 0);
         newBullet.transform.rotation = Quaternion.Euler(0f, 0f, 0f);
         BulletLogic bulletLogic = newBullet.GetComponent <BulletLogic>();
         // just values I'm making up
         bulletLogic.Initialize(BulletType.Boomerang, 10, 20, 2, 10, playerStats.playerColor, playerStats.number, playerStats.character);
         newBullet.GetComponentInChildren <SpriteRenderer>().sortingOrder = 9 - bufferIter;
     }
     for (int i = 0; i < 4; i++)
     {
         GameObject newBullet = bullets.GetBullet();
         newBullet.transform.position = new Vector3(35, -15 + (i * 8), 0);
         newBullet.transform.rotation = Quaternion.Euler(0f, 0f, 0f);
         BulletLogic bulletLogic = newBullet.GetComponent <BulletLogic>();
         // just values I'm making up
         bulletLogic.Initialize(BulletType.Boomerang, 10, 20, 2, 10, playerStats.playerColor, playerStats.number, playerStats.character);
         newBullet.GetComponentInChildren <SpriteRenderer>().sortingOrder = 9 - bufferIter;
     }
 }
Ejemplo n.º 16
0
    // Finds the distance to the kibble the cat is currently going for
    void DistanceToKibble()
    {
        if (m_CurrentTreat)
        {
            // If close enough to stop and eat the kibble
            if (Vector3.Distance(m_CurrentTreat.transform.position, gameObject.transform.position) <= 0.6f)
            {
                BulletLogic aKibble = m_CurrentTreat.GetComponent <BulletLogic>();

                if (!aKibble.GetBeingEaten() && aKibble.GetIfLanded())
                {
                    // Makes it unavailable for other cats and starts eating it
                    aKibble.SetEating();
                    StartCoroutine(EatKibble());
                }
            }
            else
            {
                ChaseTreat();
            }
        }
    }
    //Getting hit
    void OnTriggerEnter(Collider characterCollider)
    {
        //Checking collision
        if (characterCollider.GetComponent <BulletLogic>() != null)
        {
            BulletLogic bullet = characterCollider.GetComponent <BulletLogic>();

            //Checking if bullet was shot by player
            if (bullet.ShotByPlayer == true)
            {
                bullet.gameObject.SetActive(false);
                health -= bullet.playerBulletDamage;
            }

            //Checking if health if below 0 - if yes then die
            if (health <= 0 && isDead == false)
            {
                bullet.gameObject.SetActive(false);
                isDead = true;
                Destroy(gameObject);
            }
        }
    }
Ejemplo n.º 18
0
    public void CreateBullet(BulletDepot.Bullet bullet, BulletType type = BulletType.Knife)
    {
        int angle = bullet.angle + (int)playerMovement.CurrentShotAngle();
        //Debug.Log("CreateBullet(): angle =" + angle + " playerMovement.CurrentShotAngle = " + (int)playerMovement.CurrentShotAngle());  //ski

        GameObject newBullet = bullets.GetBullet();

        newBullet.transform.position = gameObject.transform.position;
        newBullet.transform.rotation = Quaternion.Euler(0, 0, angle);
        BulletLogic bulletLogic = newBullet.GetComponent <BulletLogic>();       //((GameObject)Instantiate(bulletPrefab, gameObject.transform.position, Quaternion.Euler(0, 0, angle))).GetComponent<BulletLogic>();

        if (poweredUpBullets)
        {
            bulletLogic.Initialize(type, bullet.damage * 2, bullet.speed, bullet.size, 5, playerStats.playerColor, playerStats.number, playerStats.character);
        }
        else
        {
            bulletLogic.Initialize(type, bullet.damage, bullet.speed, bullet.size, 5, playerStats.playerColor, playerStats.number, playerStats.character);
        }
        newBullet.GetComponentInChildren <SpriteRenderer>().sortingOrder = 9 - bufferIter;
        //Debug.Log("Sorting layer debug thing " + newBullet.GetComponentInChildren<SpriteRenderer>().sortingOrder);
        //Debug.Log("bullet " + newBullet.gameObject.name + " rotation = " + newBullet.transform.rotation);
    }
Ejemplo n.º 19
0
        public void SpawnSingleAt(BulletLogic logicType, BulletDraw drawType, Radial radial, Vector2 position, Color color)
        {
            int index = 0;

            for (index = 0; index < Count; index++)
            {
                if (this[index].logicType == BulletLogic.None)
                {
                    break;
                }
                else
                {
                    IO.Debug.Log("Could not spawn bullet");
                    return;
                }
            }

            this[index].logicType      = logicType;
            this[index].drawType       = drawType;
            this[index].radial         = radial;
            this[index].position       = position;
            this[index].color          = color;
            this[index].TimeSinceAwake = 0f;
        }
Ejemplo n.º 20
0
    // Update is called once per frame
    void Update()
    {
        if (m_Active)
        {
            if (m_time <= 0)
            {
                Vector3 initSpawnPoint = transform.position + m_CanonRadius * transform.forward;

                Vector3    pos           = initSpawnPoint;
                Vector3    nextDirection = transform.forward;
                Quaternion nextRotation  = transform.rotation;
                for (int i = 0; i < m_DirectionCnt; ++i)
                {
                    GameObject  newBullet      = Instantiate(m_BulletPrefab, pos, nextRotation) as GameObject;
                    BulletLogic newBulletLogic = newBullet.GetComponent <BulletLogic>();
                    newBulletLogic.m_Canon          = gameObject;
                    newBulletLogic.m_BulletLifeTime = m_BulletDuration; //added by Chris
                    newBulletLogic.m_Attack         = m_BulletAtk;      //added by Chris
                    if (m_NextDoubleAtk > 0)
                    {
                        newBulletLogic.m_Attack = m_BulletAtk * 2;
                        m_NextDoubleAtk--;
                    }
                    if (m_NextDoubleSpeed > 0)
                    {
                        newBulletLogic.m_BulletSpeed *= 2;
                        m_NextDoubleSpeed--;
                    }


                    Quaternion q = Quaternion.AngleAxis(360 / m_DirectionCnt, transform.up);
                    nextDirection = q * nextDirection;
                    nextRotation  = q * nextRotation;
                    pos           = transform.position + m_CanonRadius * nextDirection;
                }

                m_time = m_Frequency;
            }

            if (m_cd == m_bonusTime)
            {
                m_Frequency = m_Frequency / 2;
                m_time     -= m_Frequency;
            }
            else if (m_cd <= 0)
            {
                m_Frequency = m_InitFrequency;
            }

            m_cd       -= Time.deltaTime;
            m_time     -= Time.deltaTime;
            m_Duration -= Time.deltaTime;

            if (m_Health <= 0)
            {
                Destroy(gameObject);
            }
            if (m_Duration < 0)
            {
                if (m_TurnBaseManager)
                {
                    m_TurnBaseManager.GetComponent <TurnBaseManager>().RemoveCanon(gameObject);
                }
                Destroy(gameObject);
            }
        }
    }