Esempio n. 1
0
    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.gameObject.tag == "Ground")
        {
            //sFXManager.As.clip = sFXManager.effects[3];
            //sFXManager.As.Play();
        }

        if (collision.gameObject.tag == "HumanL")
        {
            Human_Left scriptH = collision.gameObject.GetComponent <Human_Left>();

            if (!scriptH.isEcolo)
            {
                return;
            }
            else
            {
                if (!scriptH.slowed)
                {
                    scriptH.slowed = true;
                    scriptH.nbrSlowed++;
                    collision.gameObject.GetComponent <Rigidbody2D>().velocity *= coefSlow.Value;
                    return;
                }

                if (scriptH.slowed)
                {
                    scriptH.nbrSlowed++;
                }
                return;
            }
        }
        if (collision.gameObject.tag == "HumanR")
        {
            Human_Right scriptH = collision.gameObject.GetComponent <Human_Right>();
            if (!scriptH.isEcolo)
            {
                return;
            }
            else
            {
                if (!scriptH.slowed)
                {
                    scriptH.slowed = true;
                    scriptH.nbrSlowed++;
                    collision.gameObject.GetComponent <Rigidbody2D>().velocity *= coefSlow.Value;
                    return;
                }
                if (scriptH.slowed)
                {
                    scriptH.nbrSlowed++;
                }
            }
        }
    }
Esempio n. 2
0
    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.gameObject.tag == "HumanR")
        {
            float velocityH = collision.gameObject.GetComponent <Rigidbody2D>().velocity.x;
            if (velocityH < 0)
            {
                totalVelocity--;
            }
            if (velocityH > 0)
            {
                totalVelocity++;
            }
            collision.gameObject.GetComponent <Rigidbody2D>().velocity = new Vector2(0, 0);

            Human_Right scriptH = collision.gameObject.GetComponent <Human_Right>();
            if (scriptH.isEcolo)
            {
                ecoloNbr++;
            }
            if (!scriptH.isEcolo)
            {
                pollueurNbr++;
            }

            humans.Add(collision.gameObject);
        }


        if (collision.gameObject.tag == "HumanL")
        {
            float velocityH = collision.gameObject.GetComponent <Rigidbody2D>().velocity.x;
            if (velocityH < 0)
            {
                totalVelocity--;
            }
            if (velocityH > 0)
            {
                totalVelocity++;
            }
            collision.gameObject.GetComponent <Rigidbody2D>().velocity = new Vector2(0, 0);

            Human_Left scriptH = collision.gameObject.GetComponent <Human_Left>();
            if (scriptH.isEcolo)
            {
                ecoloNbr++;
            }
            if (!scriptH.isEcolo)
            {
                pollueurNbr++;
            }

            humans.Add(collision.gameObject);
        }
    }
Esempio n. 3
0
    private void OnTriggerExit2D(Collider2D collision)
    {
        if (collision.gameObject.tag == "HumanL")
        {
            Human_Left scriptH = collision.gameObject.GetComponent <Human_Left>();
            if (scriptH.slowed)
            {
                Debug.Log(scriptH.nbrSlowed);
                if (scriptH.nbrSlowed == 1)
                {
                    collision.gameObject.GetComponent <Rigidbody2D>().velocity *= (1 / coefSlow.Value);
                    scriptH.slowed     = false;
                    scriptH.nbrSlowed -= 1;
                    return;
                }

                if (scriptH.nbrSlowed > 1)
                {
                    scriptH.nbrSlowed -= 1;
                    return;
                }
            }
        }
        if (collision.gameObject.tag == "HumanR")
        {
            Human_Right scriptH = collision.gameObject.GetComponent <Human_Right>();
            if (scriptH.slowed)
            {
                if (scriptH.nbrSlowed == 1)
                {
                    collision.gameObject.GetComponent <Rigidbody2D>().velocity *= (1 / coefSlow.Value);
                    scriptH.slowed     = false;
                    scriptH.nbrSlowed -= 1;
                    return;
                }

                if (scriptH.nbrSlowed > 1)
                {
                    scriptH.nbrSlowed -= 1;
                    return;
                }
            }
        }
    }
Esempio n. 4
0
    IEnumerator Die()
    {
        GetComponent <Collider2D>().enabled = false;
        transform.GetChild(0).gameObject.GetComponent <Collider2D>().enabled = false;
        foreach (GameObject human in humans)
        {
            if (human != null)
            {
                human.GetComponent <Human_Right>();
                if (human.GetComponent <Human_Right>() != null)
                {
                    //-------------------------------------------------- REDONNE VITESSE HUMAIN DROITE -------------------
                    Human_Right scriptHuman = human.GetComponent <Human_Right>();
                    bool        isSlowed    = scriptHuman.slowed;
                    bool        isBuched    = scriptHuman.buched;

                    if (!isSlowed)
                    {
                        if (!isBuched)
                        {
                            human.GetComponent <Rigidbody2D>().velocity = new Vector2(scriptHuman.speed, 0);
                        }
                        if (isBuched)
                        {
                            human.GetComponent <Rigidbody2D>().velocity = new Vector2(-scriptHuman.speed, 0);
                        }
                    }
                    if (isSlowed)
                    {
                        if (!isBuched)
                        {
                            human.GetComponent <Rigidbody2D>().velocity = new Vector2(scriptHuman.speed * coefSlow.Value, 0);
                        }
                        if (isBuched)
                        {
                            human.GetComponent <Rigidbody2D>().velocity = new Vector2(-scriptHuman.speed * coefSlow.Value, 0);
                        }
                    }
                }


                human.GetComponent <Human_Left>();
                if (human.GetComponent <Human_Left>() != null)
                {
                    //-------------------------------------------------- REDONNE VITESSE HUMAIN GAUCHE -------------------
                    Human_Left scriptHuman = human.GetComponent <Human_Left>();
                    bool       isSlowed    = scriptHuman.slowed;
                    bool       isBuched    = scriptHuman.buched;

                    if (!isSlowed)
                    {
                        if (!isBuched)
                        {
                            human.GetComponent <Rigidbody2D>().velocity = new Vector2(scriptHuman.speed, 0);
                        }
                        if (isBuched)
                        {
                            human.GetComponent <Rigidbody2D>().velocity = new Vector2(-scriptHuman.speed, 0);
                        }
                    }
                    if (isSlowed)
                    {
                        if (!isBuched)
                        {
                            human.GetComponent <Rigidbody2D>().velocity = new Vector2(scriptHuman.speed * coefSlow.Value, 0);
                        }
                        if (isBuched)
                        {
                            human.GetComponent <Rigidbody2D>().velocity = new Vector2(-scriptHuman.speed * coefSlow.Value, 0);
                        }
                    }
                }
            }

            //if(human.gameObject.tag == ("HumanR"))
            //{
            //    if (human.GetComponent<Human_Right>().slowed == false)
            //    {
            //        human.GetComponent<Rigidbody2D>().velocity = new Vector2(-1, 0);
            //    }
            //}

            //if (human.gameObject.tag == ("HumanL"))
            //{
            //    human.GetComponent<Rigidbody2D>().velocity = new Vector2(1, 0);
            //}
        }
        transform.parent.gameObject.GetComponent <ParticleSystem>().Stop();
        Color color = GetComponent <SpriteRenderer>().color;

        GetComponent <SpriteRenderer>().color = Color.black;
        yield return(new WaitForSeconds(2));

        Destroy(transform.parent.gameObject);
    }