Ejemplo n.º 1
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.A) && !isCrushing)
        {
            isCrushing = true;
            // Nervous changes
            foreach (Collider2D coll in Physics2D.OverlapCircleAll(gameObject.transform.position, 3))
            {
                if (coll.tag == "Victim")
                {
                    coll.gameObject.GetComponent <VictimControls>().SetNervous();
                }
            }
            // Spook changes
            foreach (Collider2D coll in Physics2D.OverlapCircleAll(gameObject.transform.position, 1))
            {
                if (coll.tag == "Victim")
                {
                    coll.gameObject.GetComponent <VictimControls>().SetSpook();
                }
            }
        }
        if (isCrushing)
        {
            crushDuration  += Time.deltaTime;
            renderer.sprite = crushDuration > 0 && crushDuration <= 0.0625 ? Frame2
                            : crushDuration > 0.0625 && crushDuration <= 0.125 ? Frame3
                            : crushDuration > 0.125 && crushDuration <= 0.1875 ? Frame4
                            : crushDuration > 0.1875 && crushDuration <= 0.250 ? Frame5
                            : crushDuration > 0.250 && crushDuration <= 0.3125 ? Frame6
                            : crushDuration > 0.3125 && crushDuration <= 0.3750 ? Frame7
                            : crushDuration > 0.3750 && crushDuration <= 0.4375 ? Frame8 : Frame1;
            if (crushDuration > 0.0625 && crushDuration < 0.125)
            {
                foreach (Collider2D coll in Physics2D.OverlapCircleAll(gameObject.transform.position, 1f))
                {
                    if (coll.tag == "Victim")
                    {
                        foreach (AudioSource sound in GetComponents <AudioSource>())
                        {
                            sound.Play();
                        }
                        bloodGush.Stop();
                        bloodGush.Play();
                        Object.Destroy(coll.gameObject);
                        GlobalEventHandler.SendEvent(new GameEvents.VictimDied {
                        });
                    }
                }
            }

            if (crushDuration > 0.4375)
            {
                isCrushing    = false;
                crushDuration = 0;
            }
        }
    }