Esempio n. 1
0
 void Awake() {
     BoxRef = this.gameObject.GetComponent<BoxCollider>();
     ScriptRef = ParentRef.gameObject.GetComponent<CartoonExplosionFX>();
     RigidRef = this.gameObject.GetComponent<Rigidbody>();
     ShatterRef = this.gameObject.GetComponent<ShatterOnCollision>();
   
 }
 void Start()
 {
     shatterOnCollision         = gameObject.GetComponent <ShatterOnCollision>();
     shatterTool                = gameObject.GetComponent <ShatterTool>();
     rigidbody                  = gameObject.GetComponent <Rigidbody>();
     shatterOnCollision.enabled = false;
     shatterTool.enabled        = false;
     rigidbody.constraints      = RigidbodyConstraints.FreezeAll;
 }
Esempio n. 3
0
    void Shoot()
    {
        timer = 0f;

        gunAudio.Play();

        gunLight.enabled = true;

        gunParticles.Stop();
        gunParticles.Play();

        gunLine.enabled = true;
        gunLine.SetPosition(0, transform.position);

        shootRay.origin    = transform.position;
        shootRay.direction = transform.forward;
        // Bit shift the index of the layer (8) to get a bit mask
        int layerMask = 1 << 8;

        // This would cast rays only against colliders in layer 8.
        // But instead we want to collide against everything except layer 8. The ~ operator does this, it inverts a bitmask.
        layerMask = ~layerMask;

        if (Physics.Raycast(shootRay, out shootHit, range, layerMask))
        {
            CompleteProject.EnemyHealth enemyHealth = shootHit.collider.GetComponent <CompleteProject.EnemyHealth> ();
            ShatterOnCollision          shatter     = shootHit.collider.GetComponent <ShatterOnCollision>();

            if (enemyHealth != null)
            {
                enemyHealth.TakeDamage(damagePerShot, shootHit.point);
            }
            else if (shatter != null)
            {
                shatter.Action();
            }
            gunLine.SetPosition(1, shootHit.point);
        }
        else
        {
            gunLine.SetPosition(1, shootRay.origin + shootRay.direction * range);
        }
    }
Esempio n. 4
0
    // Update is called once per frame
    void FixedUpdate()
    {
        //----------------------------------
        // Initiate
        //----------------------------------

        if (
            gestureManager.noSpellActive() &&
            leapManager.PalmNormalNearIgnore(gestureManager.calibratedDown, 0.65f, false, true, false) &&
            leapManager.PalmBetweenY(yThreshold, Mathf.Infinity) &&
            leapManager.GetFingerIsExtendedPattern(false, false, false, false, false) &&
            leapManager.GetHandGrabStrength() >= 0.8f
            )
        {
            gestureManager.activeSpell = thisSpell;
            gustProgression            = leapManager.GetPalmPosition().y;
            gestureManager.setHandColor(Color.yellow);
            gestureManager.glowController.Burst(1f);

            charge   = 0;
            released = false;

            audioManager.PlayLoop("gustLoop", handManager.audioplayerCasting);
        }

        //----------------------------------
        // Maintain
        //----------------------------------

        float palmY = leapManager.GetPalmPosition().y;

        palmWorldPosition = leapManager.GetPalmWorldPosition();
        gustCenter        = new Vector3(palmWorldPosition.x, 5f, palmWorldPosition.z);

        if (gestureManager.activeSpell.Equals(thisSpell))
        {
            //Debug.Log ("Gust is active!");
            if (
                leapManager.PalmNormalNearIgnore(gestureManager.calibratedDown, 0.85f, false, true, false) &&
                leapManager.GetFingerIsExtendedPattern(false, false, false, false, false) &&
                leapManager.GetHandGrabStrength() >= 0.6f
                //&& leapManager.PalmNearIgnore (tempPalmWorldPosition, 7f, false, true, true)
                && palmY < gustProgression + 1.5f
                )
            {
                if (charge < 0.1f)
                {
                    gestureManager.glowController.setIntensity(1f - charge * 10f);
                }
                else
                {
                    gestureManager.glowController.setIntensity(charge);
                }
                gestureManager.glowController.Flicker(charge);

                //Handle charge
                charge    = Mathf.Min(1, charge + 0.0075f);
                pulsebase = (pulsebase + (charge * 20f * Time.deltaTime)) % (2 * Mathf.PI);
                gestureManager.setHandColor(Color.Lerp(Color.white, Color.yellow, Mathf.Sin(pulsebase)));

                //If the hand is actually moving downwards, make some wind
                if (palmY < gustProgression - 1.5f)
                {
                    //Flash lights
                    FlashLights(charge);

                    if (!released)
                    {
                        audioManager.Stop(handManager.audioplayerCasting);
                        audioManager.Play("gustRelease", handManager.audioplayerCastingGust);
                        released = true;
                    }

                    gestureManager.glowController.setIntensity(0);
                    gestureManager.glowController.Burst(0.5f);


                    //Determine charge for this particular fixed update (NOTE - a different use of 'charge' than in GestureHurricane!)
                    float pull = gustProgression - palmY;

                    //Create drag
                    float searchRadiusSqr = 280.0f;

                    GameObject[] players       = GameObject.FindGameObjectsWithTag("Player");
                    GameObject[] objects       = GameObject.FindGameObjectsWithTag("Interactables");
                    GameObject[] intactObjects = GameObject.FindGameObjectsWithTag("Shatterables");

                    foreach (GameObject o in intactObjects)
                    {
                        ShatterOnCollision      scrA = o.GetComponent <ShatterOnCollision> ();
                        ShatterIndexOnCollision scrB = o.GetComponent <ShatterIndexOnCollision> ();

                        if (scrA != null || scrB != null)
                        {
                            //get pull direction (and distance to hand)
                            Vector3 dir = gustCenter - o.transform.position;

                            if (dir.sqrMagnitude <= searchRadiusSqr - Random.Range(0f, 50f))
                            {
                                IntactObject scr2 = o.GetComponentInChildren <IntactObject> ();
                                if (scr2 != null)
                                {
                                    scr2.SetHitvector(dir.normalized * 0.2f);
                                }

                                if (scrA != null)
                                {
                                    scrA.ShatterObject();
                                }
                                else if (scrB != null)
                                {
                                    scrB.ShatterObject();
                                }
                            }
                        }
                    }

                    foreach (GameObject o in objects)
                    {
                        Rigidbody rb = o.GetComponent <Rigidbody> ();
                        if (rb != null)
                        {
                            //get pull direction (and distance to hand)
                            Vector3 dir = gustCenter - rb.position;

                            if (dir.sqrMagnitude <= searchRadiusSqr)                               //Ignore if above threshold

                            //Calculate drag, based on distance to hand (reverse proportional), and scale by totalForceMultiplier
                            {
                                float force = Mathf.Clamp(searchRadiusSqr - dir.sqrMagnitude, 0f, searchRadiusSqr) * charge * pull * 6.0f;
                                //Set magnitude to force
                                dir = dir.normalized * force;
                                //Rotate pull, to create hurricane effect
                                dir = Quaternion.Euler(0f, 15f, 0f) * dir;

                                //Apply
                                rb.AddForce(dir);
                            }
                        }
                    }

                    foreach (GameObject o in players)
                    {
                        Rigidbody rb = o.GetComponent <Rigidbody> ();
                        if (rb != null)
                        {
                            //get pull direction (and distance to hand)
                            Vector3 dir = gustCenter - rb.position;
                            //Calculate drag, based on distance to hand (reverse proportional)
                            float force = Mathf.Clamp(searchRadiusSqr - dir.sqrMagnitude, 0, searchRadiusSqr) * pull * 0.001f;
                            //Set magnitude to force
                            dir = dir.normalized * force;
                            //Rotate pull, to create hurricane effect
                            dir = Quaternion.Euler(0, 30f, 0) * dir;

                            //Apply
                            rb.AddForce(dir);
                        }
                    }

                    gustProgression = palmY;
                }
            }

            else
            {
                gustProgression = -10f;                 //Incapacitate gustProgression
                gestureManager.clearActiveSpell();

                levelLight.intensity = levelLightBaseIntensity;
                gestureManager.glowController.setIntensity(0);

                if (!released)
                {
                    audioManager.Play("summonStop", handManager.audioplayerCasting);
                }
            }
        }


        //Handle flickering

        if (lightflicker > 0)
        {
            lightflicker -= 0.05f;

            //Flash the lights!
            levelLight.intensity = levelLightBaseIntensity + Random.Range(-0.4f, 2f) * lightflicker;
        }
        else
        {
            levelLight.intensity = levelLightBaseIntensity;
        }
    }