Ejemplo n.º 1
0
    void collisionCode(Collider otherCollider)
    {
        if (otherCollider.gameObject.layer == 9)   //other player

        //tries to grab movement from player
        {
            GameObject other = otherCollider.gameObject;
            other = getParent(otherCollider.gameObject);

            Movement movement = other.GetComponent <Movement>();

            //stops player from hitting themselves and their teammates
            if (movement != null && movement.player_num != player_num &&
                movement.player_num != player_num + 1)
            {
                //makes sure snowball can only hit one player
                snowballHeath -= 1;

                if (snowballHeath > -1)
                {
                    //Remove Health?
                    other.GetComponent <Health>().removeHealth(1);


                    other.GetComponentInChildren <CameraPositionFix> ().CameraShake();

                    if (other.GetComponent <PlayerType>().isSnowMan)
                    {
                        other.GetComponent <Movement> ().StartCoroutine(other.GetComponent <Movement> ().pushback());
                    }
                    other.GetComponentInChildren <HurtSound> ().play(true);

                    if (owner != null)
                    {
                        owner.HitConfirmation();
                        vibrationCode.vibrate(false, owner.inputDevice, 0.2f, 5);
                    }
                    var main = GetComponent <ParticleSystem> ().main;
                    main.startColor = new Color(255f, 0f, 0f);
                    StartCoroutine("snowBallDestruction");
                }
            }


            if (movement != null && movement.player_num != player_num &&
                movement.player_num == player_num + 1)
            {
                var main = GetComponent <ParticleSystem> ().main;
                main.startColor = new Color(255f, 0f, 0f);
                StartCoroutine("snowBallDestruction");
            }
        }

        //hit wall
        Debug.Log(otherCollider.gameObject.layer);
        if (otherCollider.gameObject.layer == 0 || otherCollider.gameObject.layer == 11)
        {
            Debug.Log("Snowball error");
            StartCoroutine("snowBallDestruction");
        }
        if (otherCollider.gameObject.layer == 12)   //dummy
        {
            otherCollider.gameObject.GetComponent <OnHitRotate>().SnowballHitRotate();
            var main = GetComponent <ParticleSystem> ().main;
            main.startColor = new Color(255f, 0f, 0f);
            StartCoroutine("snowBallDestruction");
        }
    }