Пример #1
0
    void OnTriggerEnter2D(Collider2D other)
    {
        if (other.gameObject == GameObject.Find("Red") && Red.stunTimer <= 0)
        {
            Red.health   -= 5;
            Red.stunTimer = 20;
            Red.stun      = Blue.direction * 0.2f;
            if (JarOSand.holder == other.gameObject)
            {
                JarOSand.drop();
            }
            if (Red.health <= 0)
            {
                Red.stun                 = 0;
                Red.health               = 100;
                Red.stunTimer            = 50;
                Red.currlife            -= 1;
                other.transform.position = new Vector3(50, 0, 0);
            }
        }

        if (other.gameObject.GetComponent <Skeleton>().enabled)
        {
            Destroy(other.gameObject);
        }
    }
Пример #2
0
    void OnCollisionEnter2D(Collision2D theCollision)
    {
        if (theCollision.gameObject == GameObject.Find("Red") && Red.stunTimer <= 0)
        {
            Red.health   -= 5;
            Red.stunTimer = 20;
            if (gameObject.GetComponent <SpriteRenderer>().flipX)
            {
                Red.stun = 0.2f;
            }
            else
            {
                Red.stun = -0.2f;
            }

            if (JarOSand.holder == theCollision.gameObject)
            {
                JarOSand.drop();
            }
            if (Red.health <= 0)
            {
                Red.stun      = 0;
                Red.health    = 100;
                Red.stunTimer = 50;
                Red.currlife -= 1;
                theCollision.transform.position = new Vector3(50, 0, 0);
            }
        }
        else if (theCollision.gameObject == GameObject.Find("Blue") && Blue.stunTimer <= 0)
        {
            Blue.health   -= 5;
            Blue.stunTimer = 20;
            if (gameObject.GetComponent <SpriteRenderer>().flipX)
            {
                Blue.stun = 0.2f;
            }
            else
            {
                Blue.stun = -0.2f;
            }

            if (JarOSand.holder == theCollision.gameObject)
            {
                JarOSand.drop();
            }
            if (Blue.health <= 0)
            {
                Blue.stun      = 0;
                Blue.health    = 100;
                Blue.stunTimer = 50;
                Blue.currlife -= 1;
                theCollision.transform.position = new Vector3(-50, 0, 0);
            }
        }
    }
Пример #3
0
    // Update is called once per frame
    void Update()
    {
        if (transform.position.y < -35)
        {
            if (JarOSand.holder != null)
            {
                JarOSand.drop();
            }
            GameObject.Find("jar of sand").transform.position = new Vector3(0, -6, 0);
        }

        if (holder != null)
        {
            if (holder == GameObject.Find("Blue").gameObject)
            {
                transform.position = new Vector3(holder.transform.position.x + (3 * Blue.direction), holder.transform.position.y - 2, 0);
                Blue.score        += 1;
            }
            else if (holder == GameObject.Find("Red").gameObject)
            {
                transform.position = new Vector3(holder.transform.position.x + (3 * Red.direction), holder.transform.position.y - 2, 0);
                Red.score         += 1;
            }
        }
        else
        {
            if (transform.position.y < -26 && transform.position.x < 64 && transform.position.x > -64)
            {
                gameObject.GetComponent <Rigidbody2D>().gravityScale = 0;
                gameObject.GetComponent <Rigidbody2D>().velocity     = new Vector2(0, 0);
            }
            else
            {
                gameObject.GetComponent <Rigidbody2D>().gravityScale = 1;
            }
        }
    }