Esempio n. 1
0
    private void OnTriggerEnter(Collider other)
    {
        if (!hasExploded)
        {
            //Debug.Log(other.gameObject.name);
            //other.gameObject.name = "ITS HITTING THIS";
            // Playing particle effect:
            Explode();

            if (other.gameObject.tag == "Player")
            {
                // Handler of the other player.
                PlayerHandler handler = other.gameObject.GetComponentInParent <PlayerHandler>();

                // Check what state the player is in:
                if (handler.CurrentState == StateManager.PLAYER_STATE.Mech)
                {
                    // Dealing damage to the player, then checking if their health is 0:
                    if (handler.Mech_TakeDamage(directHitDamage) == 0)
                    {
                        // Adding a mech kill to the player stats:
                        shooterHandler.PlayerStats.KilledMech();
                    }
                }
                else
                {
                    // Dealing damage to the player, then checking if their health is 0:
                    if (handler.Core_TakeDamage(directHitDamage) == 0)
                    {
                        // Killing the victim:
                        handler.IsAlive = false;

                        // Adding a kill to the core stats:
                        shooterHandler.PlayerStats.KilledCore();
                    }
                }
            }

            // Checking for splash damage:
            CheckForSplashDamage();

            // Setting the object inactive.
            this.gameObject.SetActive(false);
            hasExploded = false;
        }
    }
Esempio n. 2
0
    void Shoot()
    {
        // Playing the muzzle flash
        if (!muzzleFlash.isPlaying)
        {
            muzzleFlash.Play();
        }

        //yield return new WaitForSeconds(delay);

        float   rand  = Random.Range(-halfAngle, halfAngle) + Random.Range(-halfAngle, halfAngle);
        float   rand1 = Random.Range(-halfAngle, halfAngle) + Random.Range(-halfAngle, halfAngle);
        float   x     = rand;
        float   y     = rand1;
        Vector2 RandomRangedArea;

        RandomRangedArea = new Vector2(x, y);
        Vector3 forwardVector = firePoint2.transform.forward;
        float   randX         = Random.Range(-randXRange, randXRange);
        float   randY         = Random.Range(-randYRange, randYRange);
        float   randZ         = Random.Range(-randZRange, randZRange);

        forwardVector.x += randX;
        forwardVector.y += randY;
        forwardVector.z += randZ;

        Ray ray = new Ray();

        ray.origin    = firePoint2.transform.position;
        ray.direction = forwardVector;

        RaycastHit hit;

        bulletPool[gunAmmoShot].gameObject.SetActive(true);
        bulletPool[gunAmmoShot].Setup(playerHandler, firePoint2.transform.position, forwardVector, 100f);

        if (playerHandler.IsControllable)
        {
            Debug.DrawLine(ray.origin, ray.origin + ray.direction * 1000, Color.red, 0.1f);
            if (Physics.Raycast(ray, out hit, gunRange))
            {
                if (hit.transform.gameObject.tag == "Player")
                {
                    PlayerHandler otherPlayerHandler = GetComponentInParent <PlayerHandler>();

                    if (otherPlayerHandler.CurrentState == StateManager.PLAYER_STATE.Mech)
                    {
                        Debug.Log("Hit mech!");
                        if (playerHandler.Mech_TakeDamage((int)gunDamage) == 0)
                        {
                            playerHandler.PlayerStats.KilledMech();
                        }
                    }
                    else
                    {
                        // Dealing damage to the player, then checking if their health is 0:
                        if (playerHandler.Core_TakeDamage((int)gunDamage) == 0)
                        {
                            Debug.Log("Hit core!");
                            // Killing the victim:
                            otherPlayerHandler.IsAlive = false;

                            // Adding a kill to the core stats:
                            playerHandler.PlayerStats.KilledCore();
                        }
                    }
                }
            }
        }
    }