public void OnCollisionEnter(Collision obj)
    {
        if (obj.gameObject.tag == "Bullets")
        {
            if (_state == States.Alive && HP > 0)
            {
                var vFinal  = obj.rigidbody.mass * obj.relativeVelocity / (rigidbody.mass + obj.rigidbody.mass);
                var impulse = vFinal * rigidbody.mass;

                //Debug.Log(obj.gameObject.name + "  vFinal = " + vFinal + "(" + vFinal.magnitude + ")  impulse = " + impulse + " (" + impulse.magnitude + ")");
                HP -= obj.gameObject.GetComponent <BulletStat>().Damage *vFinal.magnitude;
                Debug.Log("HP = " + HP);

                if (HP <= 0)
                {
                    var detonator =
                        _state = States.Dead;
                    Debug.Log("Dead");
                    audio.Play();
                    _detonator.Explode();
                    Destroy(gameObject, 3);
                }
            }
        }
    }
Exemple #2
0
    void OnCollisionEnter(Collision other)
    {
        /*
         * count++;
         * if(count == 1)
         * {
         *
         *  if (other.gameObject.tag == "Enemy")
         *  {
         *      _Detonator.Explode();
         *      effectClone.transform.position = this.transform.position;
         *      effectClone.SetActive(true);
         *
         *      Destroy(gameObject, 2f);
         *  }
         * }
         */
        if (other.gameObject.tag == "target")
        {
            _Detonator.Explode();
            effectClone.transform.position = this.transform.position;
            effectClone.SetActive(true);

            Destroy(gameObject);
        }
    }
Exemple #3
0
    private void ExplodeAndDestroy()
    {
        detonation.transform.position = this.rigidbody.position;
        Detonator d = detonation.GetComponent <Detonator>();

        d.Explode();
        Destroy(gameObject);         // Destruye el invader
    }
 // Update is called once per frame
 void Update()
 {
     if (moCon.dead == true && moCon.camUn == true)
     {
         endBoom.Explode();
         Invoke("disableRender", 3);
     }
 }
Exemple #5
0
        public override void OnSpawn()
        {
            base.OnSpawn();

            if (m_Detonator != null)
            {
                m_Detonator.Explode();
            }
        }
Exemple #6
0
    private IEnumerator BlowAway()
    {
        GameObject detonator = GameObject.Find("Detonator");
        Detonator  det       = gameObject.GetComponentInChildren <Detonator> ();

        //det.gameObject.transform.parent = null;
        //transform.DetachChildren ();
        Transform[] transforms = gameObject.GetComponentsInChildren <Transform> ();
        foreach (Transform childTransform in transforms)
        {
            //Debug.Log ("Boom for: " + childTransform.gameObject.name + " Mesh: " + childTransform.name);
            childTransform.parent = null;
            MeshFilter mesh = childTransform.gameObject.GetComponent <MeshFilter> ();
            if (mesh != null)
            {
                mesh.gameObject.AddComponent(typeof(Rigidbody));
                mesh.gameObject.rigidbody.isKinematic = false;
                mesh.gameObject.rigidbody.useGravity  = true;
                mesh.gameObject.rigidbody.mass        = 10;
            }
            if (childTransform.gameObject != detonator)
            {
                // detonator kills itself
                Destroy(childTransform.gameObject, 5);
            }
        }
        //GameObject boom = GameObject.Find ("Detonator");

        //if (boom != null) {
        //yield return new WaitForSeconds(1);
        //gameObject.transform.DetachChildren ();
        //Detonator det = GameObject.Find("Detonator").GetComponent<Detonator>();
        if (det != null)
        {
            det.Explode();
        }
        else
        {
            Debug.Log("Det is null");
        }
        Destroy(gameObject, 5);

        exploded = true;
        yield return(new WaitForSeconds(3));

        //} else {
        //	Debug.Log ("Boom is null");
        //}

        //goBoom = false;
        //Transform[] childs = gameObject.GetComponentsInChildren<Transform>();
        //foreach(Transform child in childs){
        //Debug.Log("Destroy " + child.gameObject.name + " Mesh: " + child.name);
        //}
        LandingPadGroup.GetInstance().SetGameOver();
    }
Exemple #7
0
    IEnumerator Boom(Collider other)
    {
        MeshRender.materials[0].SetColor("_EmissionColor", color);
        yield return(new WaitForSeconds(0.5f));

        bomb.Explode();
        other.GetComponentInParent <Rigidbody>().AddExplosionForce(power, transform.position, radius, 3.0F);

        // mineOrder = true;
    }
    public void ExplodeAndDestroy()
    {
        Detonation.transform.position = this.transform.position;
        Detonator d = Detonation.GetComponent <Detonator>();

        d.Explode();
        Debug.Log("Player: " + bike.name + " lost!");
        Destroy(TronTrail);
        Destroy(TronTrailCollider);
        Destroy(this.bike);         // Destruye al player porque pierde
    }
    // Update is called once per frame
    void Update()
    {
        timer += Time.deltaTime;
        //det.size = explosionSize;
        if (timer >= explosionDelay) {

            spawnedExplosion = (GameObject)Instantiate (explosion, transform.position, Quaternion.identity);
            det = spawnedExplosion.GetComponent<Detonator> ();
            det.size = explosionSize;
            det.Explode ();
            Destroy (gameObject);
        }
    }
Exemple #10
0
    public void ExplodeAndDestroy()
    {
        this.player = gameObject;

        if (this.player != null)
        {
            Detonation.transform.position = this.transform.position;
            Detonator d = Detonation.GetComponent <Detonator>();
            d.Explode();
            Debug.Log("Perdiste Capo!");
            InvadersGameData.gameLost = true;
            Destroy(this.player);             // Destruye al player porque pierde
        }
    }
Exemple #11
0
    void OnTriggerEnter(Collider other)
    {
        string tagName = other.gameObject.tag;

        if (tagName == "Zombie")
        {
            other.gameObject.GetComponent <ZombieController>().TakeDamage(damage);
        }
        else if (tagName == "Human")
        {
            other.gameObject.GetComponent <HumanController>().TakeDamage(damage);
        }

        detonator.Explode();
    }
Exemple #12
0
 public void destroy()
 {
     life = 0;
     detonator.Explode();
     if (audioClip)
     {
         AudioSource.PlayClipAtPoint(audioClip, player.transform.position, 2f);
     }
     if (this == player.objectiveEnemy)
     {
         player.objectiveActive = false;
         Debug.Log("Objective killed");
     }
     player.enemyIsVisible(this, false);
     player.removeEnemy(this);
     Destroy(this.gameObject, 1);
 }
Exemple #13
0
    public void Explode()
    {
        if (count > 0)
        {
            return;
        }

        // Dont know why detonator dont work on the device
        detonator.gameObject.transform.position = gameObject.transform.position;
        detonator.Explode();

        // Explode Effect by particle
        // Instantiate(particle, gameObject.transform.position, Quaternion.identity);

        Destroy(gameObject, 1.0f);
        gameManager.IncreaseHumanDead();
        count++;
    }
Exemple #14
0
    private void fire()
    {
        GameObject player  = GameObject.Find("Junkman");
        Junkman    jm      = player.GetComponent <Junkman>();
        GameObject det_obj = player.transform.Find("DetonatorFire").gameObject;
        Detonator  det     = det_obj.GetComponent <Detonator>();

        det.Explode();

        det_obj.GetComponent <AudioSource>().Play();

        applyDamage();

        if (!jm.isShieldActive())
        {
            damageEffectOn();
        }
    }
Exemple #15
0
 void OnTriggerEnter(Collider other)
 {
     if (!paused)
     {
         if (other.tag == "WallDestroyer")
         {
             Destroy(gameObject);
         }
         else if (other.tag == "Player")
         {
             AtomicDetonation.transform.position = other.transform.position;
             Detonator d = AtomicDetonation.GetComponent <Detonator>();
             d.Explode();
             InvadersGameData.gameLost = true;
             Destroy(other.gameObject);           // Destruye al player
             Destroy(gameObject);                 // Destruye el rocket
         }
     }
 }
    void OnCollisionEnter(Collision col)
    {
        //Debug.Log (col.gameObject.name);
        //should just use collision layers
        if (col.gameObject.GetComponent <Car>() != null && !is_car_dead_)
        {
            //make car fall
            this.setCarDead();

            GameObject c         = (GameObject)Instantiate(Resources.Load("Detonator-Base"));
            Detonator  explosion = c.GetComponent <Detonator>();
            explosion.Explode();

            audio_source_.PlayOneShot(audio_source_.clip);

            //Vector3 explosivePosition = new Vector3(this.transform.position.x,this.transform.position.y +.5f,this.transform.position.z);
            //this.gameObject.rigidbody.AddExplosionForce(500,explosivePosition,1.0f);
        }
        //else if (col)
    }
Exemple #17
0
    public void Detonate()
    {
        if (!hasDetonated)
        {
            detonator.Explode();
            Debug.Log("boom");
            hasDetonated = true;
            GetTimer().StopTimer();
            SceneManager.Instance.radio.StopMusic();
            foreach (StatusLight statusLight in StatusLights)
            {
                statusLight.SetInactive();
            }

            foreach (var hand in GameObject.FindObjectsOfType(typeof(SixenseHandController)))
            {
                ((SixenseHandController)hand).m_pickupZone.Drop();
                ((SixenseHandController)hand).gameObject.SetActive(false);
            }

            SceneManager.Instance.StartFade();
        }
    }
Exemple #18
0
    // Collision Detector
    void OnTriggerEnter(Collider other)
    {
        if (other.gameObject.tag == "Ring")
        {
            other.gameObject.SetActive(false);
            count++;
            setCountText();
        }

        if (other.gameObject.tag == "Finish")
        {
            objectiveDoneText.text  = "Course Finished!";
            ringsCollectedText.text = "Collected: " + count.ToString() + "/" + countObjectives.ToString();
        }

        if (other.gameObject.tag == "Terrain")
        {
            detonator.Explode();
            explosionSound.Play();
            endText.text   = "Game Over";
            Time.timeScale = 0;
        }
    }
Exemple #19
0
    void Update()
    {
        //KEEP AT THE TOP
        if (gameStarted && Input.GetKeyDown(KeyCode.Escape))
        {
            Application.Quit();
        }


        if (endingThreeOfThreeStarted)
        {
            hudPanel.SetActive(false);
            gameOverPanelEnding3.SetActive(true);
            fpsController.LockKeyboardMove();
        }

        if (endingTwoOfThreeStarted)
        {
            hudPanel.SetActive(false);
            asteroidField1.transform.position = player.transform.position;

            /* //Rotate player to top of screen
             * if (Time.deltaTime >= ONE_FRAME_60FPS) { // or 1/60th a frame
             *  Vector3 eulerAngles = player.transform.rotation.eulerAngles;
             *
             *  Debug.Log("player val = " + player.transform.rotation.eulerAngles.y);
             *  Debug.Log("cam val = " + transform.rotation.eulerAngles.x);
             *
             *  if (player.transform.rotation.eulerAngles.y > 86f) {
             *      eulerAngles.y -= ((player.transform.rotation.eulerAngles.y - 86f) / 180f);
             *  }
             *
             *  if (player.transform.rotation.eulerAngles.y < 86f) {
             *      eulerAngles.y += ((86f - player.transform.rotation.eulerAngles.y) / 180f);
             *  }
             *
             *
             *  if (player.transform.rotation.eulerAngles.x > 287f) {
             *      eulerAngles.x -= ((player.transform.rotation.eulerAngles.x - 86f) / 180f);
             *  }
             *
             *  if (player.transform.rotation.eulerAngles.x < 287f) {
             *      eulerAngles.x += ((86f - player.transform.rotation.eulerAngles.x) / 180f);
             *  }
             *
             *
             *
             *  Debug.Log(eulerAngles.x + ", " + eulerAngles.y);
             *  player.transform.rotation = Quaternion.Euler(0f, eulerAngles.y, 0f);
             *  transform.rotation = Quaternion.Euler(eulerAngles.x, 180f, 180f);
             * }*/

            return;
        }

        /////////////////////////////////////////////////////////////////
        //// Player has fallen of ledge into oblivion, show asteroids
        /////////////////////////////////////////////////////////////////
        if (player.transform.position.y <= -100f)
        {
            fpsController.LockKeyboardMove();
            //fpsController.LockMouseLook();
            endingTwoOfThreeStarted = true;
            asteroidField1.SetActive(true);
            asteroidField1.transform.position = player.transform.position;
            hudPanel.SetActive(false);
            gameOverPanelEnding2.SetActive(true);
            endGameRotationYStart = player.transform.rotation.eulerAngles.y;
            endGameRotationXStart = transform.rotation.eulerAngles.x;
        }

        /*
         *  GAME STARTED
         */
        if (largeShip.transform.position.y <= 300f && Input.anyKey && !gameObject.GetComponentInParent <FirstPersonController>().isActiveAndEnabled)
        {
            gameObject.GetComponentInParent <FirstPersonController>().enabled = true;
            gameStarted = true;
            if (largeShip.transform.position.y >= 300f)
            {
                Vector3 t = largeShip.transform.position;
                t.y = 300;
                largeShip.transform.position = t;
            }

            fpsController.LockKeyboardMove();
        }

        if (powerStartCountDown)
        {
            powerSecondsLeft -= Time.deltaTime;
            powerPercent      = (powerSecondsLeft / powerSecondsStart) * powerStartPercent;

            if (!endingOneOfThreeStarted && powerPercent < 0.025f)
            {
                endingThreeOfThreeStarted = true;
                powerPercent = 0.0f;
            }

            hudPowerText.SetText(powerPercent.ToString("0.00") + "%");
        }

        if (digitalGlitch.intensity <= 0)
        {
            if (tiltShift.isActiveAndEnabled)
            {
                tiltShift.enabled      = false;
                bloomAndFlares.enabled = false;
                ramp.enabled           = false;
                analogGlitch.enabled   = false;
                digitalGlitch.enabled  = false;
            }
        }

        if (gameStarted)
        {
            if (teleportGunFired)
            {
                if (Vector3.Distance(teleportBlast.transform.position, GetComponentInChildren <Transform>().position) > 13)
                {
                    ///Debug.Log("Shit is far enough away");
                    ///

                    //massiveRippleEffect.transform.position = teleportBlast.transform.position;
                    //massiveRippleEffect.transform.rotation = Quaternion.Euler(lastTeleportBlastVector.x, lastTeleportBlastVector.y, lastTeleportBlastVector.z);
                    //massiveRippleEffect.SetActive(true);
                }

                //Vector3 t = teleportBlast.transform.position;
                //t.z += .05f;
                //teleportBlast.transform.position = t;
            }


            if (hasTeleportGun)
            {
                endingOneOfThreeStarted = true;
                gameOverPanelEnding1.SetActive(true);
                hudPanel.SetActive(false);
                fpsController.LockKeyboardMove();

                if (Input.GetMouseButtonDown(0) || Input.GetMouseButtonDown(1))   //Either mouse button 1 or 2
                //Debug.Log("fire!!!!!!!!");

                {
                    Transform t = GetComponentInChildren <Transform>();
                    //Debug.Log(t.position.ToString());

                    //Debug.Log(" ");
                    //Debug.Log(t.rotation.eulerAngles.ToString());
                    //Debug.Log(t.rotation.ToString());
                    lastTeleportBlastVector          = t.rotation.eulerAngles;
                    teleportBlast.transform.position = t.position;
                    teleportBlast.transform.rotation = t.rotation;
                    teleportBlast.SetActive(true);

                    teleportGunFired = true;
                }
            }

            if (!setGameStartedAt)
            {
                secondsOfAfterGameStarted = Time.time;
                setGameStartedAt          = true;
            }

            if (Time.time > secondsOfAfterGameStarted + transitionAfterGameStartedSeconds)
            {
                titlePanel.SetActive(false);
            }

            mainMenuAsteroids.SetActive(false);

            /////////////////////////////////////////////////
            /// Hit Ground After falling out of big ship
            /////////////////////////////////////////////////
            if (characterController.isGrounded)
            {
                if (!hitGroundForFirstTime)
                {
                    fpsController.UnlockMouseLook();
                    fpsController.UnlockKeyboardMove();
                    cameraShake.shakeDuration = 2;
                    puffOfSmokeDetonator.Explode();

                    powerStartCountDown = true;
                    hudPanel.SetActive(true);
                    hitGroundForFirstTime = true;
                }
            }

            if (animationMainMenuPressAnyKeyTextAlphaFadeOutStart >= 0)
            {
                animationMainMenuPressAnyKeyTextAlphaFadeOutStart -= 0.3f * (1f / (1.5f / Time.deltaTime));

                digitalGlitch.intensity           = digitalGlitch.intensity <= 0 ? 0 : animationMainMenuPressAnyKeyTextAlphaFadeOutStart;
                analogGlitch.scanLineJitter       = analogGlitch.scanLineJitter <= 0 ? 0 : animationMainMenuPressAnyKeyTextAlphaFadeOutStart;
                analogGlitch.verticalJump         = analogGlitch.verticalJump <= 0 ? 0 : animationMainMenuPressAnyKeyTextAlphaFadeOutStart;
                analogGlitch.horizontalShake      = analogGlitch.verticalJump <= 0 ? 0 : animationMainMenuPressAnyKeyTextAlphaFadeOutStart;
                analogGlitch.colorDrift           = analogGlitch.colorDrift <= 0 ? 0 : animationMainMenuPressAnyKeyTextAlphaFadeOutStart;
                noiseAndGrain.intensityMultiplier = noiseAndGrain.intensityMultiplier <= 0 ? 0 : animationMainMenuPressAnyKeyTextAlphaFadeOutStart;
                tiltShift.blurArea            = tiltShift.blurArea <= 0 ? 0 : animationMainMenuPressAnyKeyTextAlphaFadeOutStart * 15f;
                bloomAndFlares.bloomIntensity = bloomAndFlares.bloomIntensity <= 0 ? 0 :animationMainMenuPressAnyKeyTextAlphaFadeOutStart;
                ramp.opacity = ramp.opacity <= 0 ? 0 : animationMainMenuPressAnyKeyTextAlphaFadeOutStart;


                animationMainMenuTitleTextAlphaFadeOutStart -= 0.3f * (1f / (1.5f / Time.deltaTime));
                mainMenuPresAnyToStart.SetAlpha(animationMainMenuPressAnyKeyTextAlphaFadeOutStart);
                mainMenuTitle.SetAlpha(animationMainMenuTitleTextAlphaFadeOutStart);
            }
        }
        else
        {
            if (largeShip.transform.position.y >= 300f)
            {
                Vector3 t = largeShip.transform.position;
                t.y -= (animationGameMenuLargeShipStartBeforeFadeInPositionY - 300f) * (1f / (5f / Time.deltaTime));
                largeShip.transform.position = t;
            }
            else
            {
                if (mainMenuTitleTextAlphaStart <= 0.3f)
                {
                    mainMenuTitleTextAlphaStart += 0.3f * (1f / (2f / Time.deltaTime));
                    mainMenuTitle.SetAlpha(mainMenuTitleTextAlphaStart);
                    animationMainMenuTitleTextAlphaFadeOutStart = mainMenuTitleTextAlphaStart;
                }
                else
                {
                    if (mainMenuPressAnyKeyTextAlphaStart <= 0.28f)
                    {
                        mainMenuPressAnyKeyTextAlphaStart += 0.28f * (1f / (2f / Time.deltaTime));
                        mainMenuPresAnyToStart.SetAlpha(mainMenuPressAnyKeyTextAlphaStart);
                    }
                }
            }

            /*if (Time.deltaTime >= ONE_FRAME_60FPS) { // or 1/60th a frame
             *
             *  //if(showPolyNaut && mainMenuAlphaStart <= .3) {
             *  //    mainMenuAlphaStart += 0.0065f;
             *  //    mainMenuTitle.SetAlpha(mainMenuAlphaStart);
             *  //    mainMenuPresAnyToStart.SetAlpha(mainMenuAlphaStart);
             *  //}
             *
             *  if (largeShip.transform.position.y >= 300f) {
             *      Vector3 t = largeShip.transform.position;
             *      t.y -= 6f;
             *      largeShip.transform.position = t;
             *  } //else {
             *    //  showPolyNaut = true;
             *  //}
             * }*/
        } //If game started, else you're in the menu
    }     //Update()
Exemple #20
0
    public void Update()
    {
        float input_vert = Input.GetAxis("Vertical");
        float input_horz = Input.GetAxis("Horizontal");

        if (input_vert > 0 && input_vert <= 1)
        {
            brake          = 0f;
            deacceleration = deacSpeed;
            acceleration  += accIncrease;
            speed         += acceleration;

            if (speed > maxSpeed)
            {
                speed = maxSpeed;
            }

            if (acceleration > 0.1f)
            {
                acceleration = 0.1f;
            }

            playLoud();
        }
        else if (input_vert < 0 && input_vert >= -1)
        {
            if (speed == 0.0f)
            {
                deacceleration = deacSpeed;
                acceleration  += accIncrease;
                speed         -= acceleration;

                if (speed < minSpeed)
                {
                    speed = minSpeed;
                }

                if (acceleration < -0.1f)
                {
                    acceleration = -0.1f;
                }
            }
            else
            {
                acceleration = 0f;
                brake       += brakeIncrease;

                speed -= brake;

                if (speed < minSpeed)
                {
                    speed = minSpeed;
                }

                if (acceleration < -0.1f)
                {
                    acceleration = -0.1f;
                }
            }

            playLoud();
        }
        else
        {
            if (speed > 0f)
            {
                speed          -= deacceleration;
                deacceleration += deacIncrease;

                if (speed < 0f)
                {
                    speed = 0f;
                }
            }
            else if (speed < 0f)
            {
                speed          += deacceleration;
                deacceleration += deacIncrease;

                if (speed > 0f)
                {
                    speed = 0f;
                }
            }
            else
            {
                deacceleration = deacSpeed;
                speed          = 0f;
                acceleration   = 0f;
                brake          = 0f;
            }

            playQuiet();
        }

        //rigidbody.AddForce(transform.rotation * new Vector3(0f, 0f, force * input_vert));

        //rigidbody.AddTorque(transform.rotation * new Vector3(0f, torque * input_horz, 0f));

        if (!GameGlobals.gameOver)
        {
            float angle = Mathf.Asin(Mathf.Sign(input_vert) * input_horz);

            transform.RotateAround(transform.position, Vector3.up, angle * 0.8f);

            if (angle >= 90 && angle <= 270)
            {
                transform.Translate(0, 0, -speed * Time.deltaTime);
            }
            else
            {
                transform.Translate(0, 0, speed * Time.deltaTime);
            }

            if (transform.rotation.x <= -45 || transform.rotation.x >= 45)
            {
                Quaternion targetRot = Quaternion.LookRotation(new Vector3(0, transform.rotation.y, transform.rotation.z));
                transform.rotation = Quaternion.Slerp(transform.rotation, targetRot, 0.1f);
            }

            if (transform.rotation.z <= -45 || transform.rotation.z >= 45)
            {
                Quaternion targetRot = Quaternion.LookRotation(new Vector3(transform.rotation.x, transform.rotation.y, 0));
                transform.rotation = Quaternion.Slerp(transform.rotation, targetRot, 0.1f);
            }

            if (Input.GetKey(KeyCode.R))
            {
                resetPosition();
                return;
            }

            //print("pos: " + transform.localPosition.y + " sampleHeight: " + GameObject.Find("Terrain").GetComponent<Terrain>().SampleHeight(transform.localPosition));

            float sampleHeight = GameObject.Find("Terrain").GetComponent <Terrain>().SampleHeight(transform.position);

            if (alive)
            {
                if ((transform.position.y < GameObject.Find("Terrain").GetComponent <Terrain>().SampleHeight(transform.position) + waterLevel) && sampleHeight < 10)
                {
                    alive = false;
                    Detonator det = this.transform.Find("DetonatorExplosion").gameObject.GetComponent <Detonator>();
                    det.Explode();
                    GameGlobals.pauseTime();
                    Invoke("Respawn", 2f);
                }
            }
        }
    }
Exemple #21
0
 void OnTriggerEnter(Collider other)
 {
     Debug.Log("Collision!");
     detonator.Explode();
     //Network.Destroy(gameObject);
 }
Exemple #22
0
    public void calculateDamage()
    {
        //Debug.Log("Hit " + hit.collider.gameObject.name);

        if (hit.collider.gameObject.Equals(shooter.gameObject))
        {
            return;
        }

        Quaternion hitRotation = Quaternion.FromToRotation(Vector3.up, hit.normal);

        if (hit.transform.gameObject.GetComponent <Rigidbody>() != null)
        {
            hit.transform.gameObject.GetComponent <Rigidbody>().AddForce(hit.normal * -HitStrength);
        }
        if (hit.transform.tag == "Explosive")
        {
            if ((Detonator)hit.transform.gameObject.GetComponent("Detonator") != null)
            {
                Detonator target = (Detonator)hit.transform.gameObject.GetComponent("Detonator");
                try {
                    target.Explode();
                } catch (System.SystemException e) {
                    Debug.LogError("Detonator failed inside Weapon");
                    Debug.LogError(e.ToString());
                }
            }
            if (hit.transform.gameObject.GetComponent("AudioSource") != null)
            {
                AudioSource targetSound = (AudioSource)hit.transform.gameObject.GetComponent("AudioSource");
                targetSound.Play();
            }
            if (hit.transform.gameObject.GetComponent <ExplosiveDamage>() != null)
            {
                hit.transform.gameObject.GetComponent <ExplosiveDamage>().explode();
            }
        }
        else if (hit.transform.tag == "Combatant")
        {
            if (hit.transform.gameObject.GetComponent("AudioSource") != null)
            {
                AudioSource targetSound = (AudioSource)hit.transform.gameObject.GetComponent("AudioSource");
                targetSound.Play();
            }
            if (hit.transform.gameObject.GetComponent("EnemyHealth") != null)
            {
                EnemyHealth enemyHealth = (EnemyHealth)hit.transform.gameObject.GetComponent("EnemyHealth");
                enemyHealth.damageAsCombatant(Damage, shooter, DamageCause.Shot);
                if (debug)
                {
                    MonoBehaviour.print("Dealt " + Damage.ToString() + " Damage to " + hit.transform.gameObject.name);
                }
            }
            if (hit.transform.gameObject.GetComponent <Health>() != null)
            {
                Health enemyHealth = hit.transform.gameObject.GetComponent <Health>();
                enemyHealth.Damage(Damage, DamageCause.Shot);
                if (debug)
                {
                    MonoBehaviour.print("Dealt " + Damage.ToString() + " Damage to " + hit.transform.gameObject.name);
                }
            }
            if (hit.transform.FindChild("Camera") != null)
            {
                if (hit.transform.FindChild("Camera").gameObject.GetComponent <Health>() != null)
                {
                    Health enemyHealth = hit.transform.FindChild("Camera").gameObject.GetComponent <Health>();
                    enemyHealth.Damage(Damage, DamageCause.Shot);
                    if (debug)
                    {
                        MonoBehaviour.print("Dealt " + Damage.ToString() + " Damage to " + hit.transform.gameObject.name);
                    }
                }
            }
            GameObject newBlood = (GameObject)MonoBehaviour.Instantiate(BloodSpray, hit.point, hitRotation);
            newBlood.transform.parent = hit.transform;
            newBlood.transform.Translate(0, (float)0.05, 0);
        }
        else if (hit.transform.gameObject.GetComponent <ShatterableGlass>() != null)
        {
            ShatterableGlass pane = hit.transform.gameObject.GetComponent <ShatterableGlass>();
            pane.shoot(hit, HitStrength);
            if (debug)
            {
                MonoBehaviour.print("Shot glass pane " + pane.name);
            }
        }
        else if (hit.transform.gameObject.GetComponent <SplashingWater>() != null)
        {
            SplashingWater pane = hit.transform.gameObject.GetComponent <SplashingWater>();
            pane.Splash(hit.point);
            if (debug)
            {
                MonoBehaviour.print("Shot Water " + pane.name);
            }
        }
        else if (hit.transform.gameObject.GetComponent <PenetrableCover>() != null)
        {
            if (debug)
            {
                MonoBehaviour.print("Shot penetrable target " + hit.transform.gameObject.name);
            }
            BulletHit b = hit.transform.gameObject.GetComponent <PenetrableCover>().catchBullet(this);
            //this = hit.transform.gameObject.GetComponent<PenetrableCover>().catchBullet(this);

            b.calcHit();                     //This is what ccauses the refracted/reflected bullet to actualy start moving.
        }
        else
        {
            if (debug)
            {
                MonoBehaviour.print("Shot " + hit.transform.name);
            }


            GameObject newBulletHole = (GameObject)MonoBehaviour.Instantiate(BulletHole, hit.point, hitRotation);
            newBulletHole.transform.parent = hit.transform;
            newBulletHole.transform.Translate(0, (float)0.05, 0);
            hitRotation.x = hitRotation.x + 270;

            GameObject newDust = (GameObject)MonoBehaviour.Instantiate(DirtSpray, hit.point, hitRotation);
            newDust.transform.parent = hit.transform;
            newDust.transform.Translate(0, (float)0.05, 0);
        }
    }
Exemple #23
0
    public bool Shoot(Camera Gun)
    {
        if (CurAmmo > 0 /*TODO Modify:  && !vehicle.riding*/ && !isFiring)
        {
            CurAmmo -= 1;
            ((AudioSource)mainObject.GetComponent("AudioSource")).Play();

            //Debug.Log("Setting anim clock to " + ((int)(30/(7.5*FireRateAsPercent / 100))) +
            //	", or " + (30/(7.5*FireRateAsPercent / 100)));
            //Debug.Log("Acheived via (30/(7.5*(" + FireRateAsPercent + "/100)))" );
            //Debug.Log("Acheived via " + 30/(7.5*FireRateAsPercent/100));

            AnimClock = (int)(30 / (7.5 * FireRateAsPercent / 100));
            ShotDelay = (int)(30 / (7.5 * FireRateAsPercent / 100));

            isFiring = true;
            for (int i = 0; i < numOfShots; i++)
            {
                Vector2    position = Random.insideUnitCircle;
                int        x        = (int)(position.x * xSpread);
                int        y        = (int)(position.y * yspread);
                Ray        ray      = Gun.ScreenPointToRay(new Vector3(Screen.width / 2 + x, Screen.height / 2 + y, 0));
                RaycastHit hit;
                if (Physics.Raycast(ray, out hit, 100))
                {
                    Quaternion hitRotation = Quaternion.FromToRotation(Vector3.up, hit.normal);

                    if (hit.transform.gameObject.GetComponent <Rigidbody>() != null)
                    {
                        hit.transform.gameObject.GetComponent <Rigidbody>().AddForce(hit.normal * -HitStrength);
                    }

                    if (hit.transform.tag == "Explosive")
                    {
                        if ((Detonator)hit.transform.gameObject.GetComponent("Detonator") != null)
                        {
                            Detonator target = (Detonator)hit.transform.gameObject.GetComponent("Detonator");
                            target.Explode();
                        }
                        if (hit.transform.gameObject.GetComponent("AudioSource") != null)
                        {
                            AudioSource targetSound = (AudioSource)hit.transform.gameObject.GetComponent("AudioSource");
                            targetSound.Play();
                        }
                    }
                    else if (hit.transform.tag == "Enemy")
                    {
                        if (hit.transform.gameObject.GetComponent("AudioSource") != null)
                        {
                            AudioSource targetSound = (AudioSource)hit.transform.gameObject.GetComponent("AudioSource");
                            targetSound.Play();
                        }
                        if (hit.transform.gameObject.GetComponent("EnemyHealth") != null)
                        {
                            EnemyHealth enemyHealth = (EnemyHealth)hit.transform.gameObject.GetComponent("EnemyHealth");
                            enemyHealth.Health -= Damage;
                            MonoBehaviour.print("Dealt " + Damage.ToString() + " Damage to " + hit.transform.gameObject.name);
                        }
                        GameObject newBlood = (GameObject)MonoBehaviour.Instantiate(BloodSpray, hit.point, hitRotation);
                        newBlood.transform.parent = hit.transform;
                        newBlood.transform.Translate(0, (float)0.05, 0);
                    }
                    else
                    {
                        GameObject newBulletHole = (GameObject)MonoBehaviour.Instantiate(BulletHole, hit.point, hitRotation);
                        newBulletHole.transform.parent = hit.transform;
                        newBulletHole.transform.Translate(0, (float)0.05, 0);
                        hitRotation.x = hitRotation.x + 270;
                        GameObject newDust = (GameObject)MonoBehaviour.Instantiate(DirtSpray, hit.point, hitRotation);
                        newDust.transform.parent = hit.transform;
                        newDust.transform.Translate(0, (float)0.05, 0);
                    }
                }
            }
            return(true);
        }
        return(false);
    }