Esempio n. 1
0
    private void Fire()
    {
        // Minus bulet from ammosystem
        ammosystem.AmmoFire();

        //Update the overheat bar
        overheat.OverheatbarUpdate();

        //Creating Bullet Spread
        Vector3 FinalPosition = Input.mousePosition;

        randomnumber = Random.Range(0, firingimages.Count);
        GameObject firing = Instantiate(firingimages[randomnumber], PointerPosition, Quaternion.identity) as GameObject;

        firing.SetActive(true);
        firing.transform.SetParent(canvas.transform);

        //Wiimote detected and connected , Use Wiimote's IR Position Instead
        if (wiimote != null)
        {
            //Setting final position to IR's detected position
            float[] pointer = wiimote.Ir.GetPointingPosition();

            //Mapping the position to screen
            FinalPosition.x = pointer[0] * Screen.width;
            FinalPosition.y = pointer[1] * Screen.height;
        }

        //print(FinalPosition);
        FinalPosition.x += Random.Range(-currentBulletSpread, currentBulletSpread);
        FinalPosition.y += Random.Range(-currentBulletSpread, currentBulletSpread);

        //Creating Ray based on final calculated position
        Ray ray = Camera.main.ScreenPointToRay(FinalPosition);

        RaycastHit hit;

        //Checking if Ray has hit
        if (Physics.Raycast(ray, out hit))
        {
            EffectsHandler.EffectResponse(hit);

            //If it has a rigidbody
            if (hit.rigidbody != null)
            {
                hit.rigidbody.AddForce(((hit.point + hit.normal) - Camera.main.transform.position).normalized * BulletForce);
            }

            if (hit.collider.gameObject.GetComponent <Enemy>() != null)
            {
                //Hit the bottom of the tank for lesser points
                ScoreManager.AddCurrentScore(ScoreManager.ScoreType.BodyShot);
                SoundManager.PlaySoundEffect(SoundManager.SoundEffect.HitEnemy);
                ScoreManager.Multiply();
                hit.transform.SendMessage("Injure", DamageOfBullet, SendMessageOptions.DontRequireReceiver);
            }
            else if (hit.collider.gameObject.GetComponent <EnemyBoss>() != null)
            {
                ScoreManager.Multiply();
                hit.transform.SendMessage("Injure", DamageOfBullet, SendMessageOptions.DontRequireReceiver);
            }
            else if (hit.collider.gameObject.GetComponent <ShootingBarrel>() != null)
            {
                //Hit the top of the tank for more points
                ScoreManager.AddCurrentScore(ScoreManager.ScoreType.TopShot);
                SoundManager.PlaySoundEffect(SoundManager.SoundEffect.HitEnemy);
                ScoreManager.Multiply();
                hit.transform.SendMessage("Injure", DamageOfBullet, SendMessageOptions.DontRequireReceiver);
            }
            else if (hit.collider.gameObject.tag == "TrafficLight")
            {
                //The trafficlight sound will only play by chance
                random = Random.Range(0, 11);
                if (random == 0)
                {
                    SoundManager.PlaySoundEffect(SoundManager.SoundEffect.TrafficLight);
                }
            }
            else if (hit.collider.gameObject.GetComponent <Weakpoint>() != null)
            {
                //Hit the weakpoint of the tank
                ScoreManager.Multiply();
                hit.transform.SendMessage("Cancel", 1, SendMessageOptions.DontRequireReceiver);
            }
            else
            {
                hit.transform.SendMessage("Injure", DamageOfBullet, SendMessageOptions.DontRequireReceiver);
            }
        }
        else
        {
            ScoreManager.ResetMultiplier();
        }

        //Play the shooting sound effect
        SoundManager.PlaySoundEffect(SoundManager.SoundEffect.Fire);

        fireTimer            = 0.0f;                                //Resetting the Timer
        currentBulletSpread += Time.deltaTime * SpreadIncreaseRate; //Increasing spread of bullet
        if (currentBulletSpread > MaxBulletSpreadRange)
        {
            currentBulletSpread = MaxBulletSpreadRange;
        }
    }