コード例 #1
0
    void OnTriggerEnter(Collider other)
    {
        if (other.tag == "Player")
        {
            if (gameObject.name == "Heart(Clone)")
            {
                // Increase health of player
                playerHealth = other.GetComponentInParent <PlayerHealthAmmo>();
                playerHealth.PickUpHeart(healthBoost);
            }
            else if (gameObject.name == "ThimbleHelm(Clone)")
            {
                playerControllerBen = other.GetComponentInParent <PlayerControllerBen>();
                // Acivate helm on player
                playerControllerBen.helmActive = true;
                playerControllerBen.helmTimer  = powerUpTimer;
            }
            else if (gameObject.name == "Shield(Clone)")
            {
                playerControllerBen = other.GetComponentInParent <PlayerControllerBen>();
                // Acivate shield on player
                playerControllerBen.shieldActive = true;
                playerControllerBen.shieldTimer  = powerUpTimer;
            }

            Destroy(gameObject);
        }
    }
コード例 #2
0
    public void Setup()
    {
        // Get references to the components.
        playerController = instance.GetComponent <PlayerControllerBen>();
        playerHealthAmmo = instance.GetComponent <PlayerHealthAmmo>();

        // Set the player numbers to be consistent across the scripts.
        playerController.playerNumber = playerNumber;

        // Create a string using the correct color that says 'PLAYER 1' etc based on the character's color and the player's number.
        coloredPlayerText = "<color=#" + ColorUtility.ToHtmlStringRGB(playerColor) + ">PLAYER" + "</color>";

        playerHealthAmmo.playerArrowUI.color = playerColor;

        // Get all of the renderers of the character.
        MeshRenderer[] renderers = instance.GetComponentsInChildren <MeshRenderer>();

        // Go through all the renderers...
        for (int i = 0; i < renderers.Length; i++)
        {
            // ... set the shield color to the default color...
            if (renderers[i].gameObject.name == "Shield")
            {
                renderers[i].material = shieldMat;
            }
            else if (renderers[i].gameObject.tag == "ThimbleHelm")
            {
                renderers[i].material.color = helmMat.color;
            }
            // ... set the eye color to black...
            else if (renderers[i].gameObject.tag == "Eye")
            {
                renderers[i].material.color = Color.black;
            }
            else
            {
                // ... and set their material color to the color specific to this character.
                renderers[i].material.color = playerColor;
            }
        }
    }
コード例 #3
0
    void OnTriggerEnter(Collider other)
    {
        hitVel = rb.velocity;
        hitDir = rb.transform.forward;

        if (other.tag == "Player")
        {
            targetRigidbody     = other.GetComponentInParent <Rigidbody>();
            playerControllerBen = targetRigidbody.GetComponent <PlayerControllerBen>();
            playerHealthAmmo    = targetRigidbody.GetComponent <PlayerHealthAmmo>();

            // If the needle has been thrown and has hit another player
            if (!collectable)
            {
                // Read the targeted player's health and damage/kill it
                if (!playerControllerBen.helmActive)
                {
                    if (playerHealthAmmo.isDead)
                    {
                        tempDeathParticle = Instantiate(playerDeathParticles, other.transform.position, other.transform.rotation) as ParticleSystem;
                        tempDeathParticle.Play();
                        Destroy(tempDeathParticle.gameObject, 2f);
                    }
                    else
                    {
                        playerHealthAmmo.TakeDamage(damage);
                        SoundManager.instance.RandomizeSfx(0.9f, playerHitSounds).Play();
                        // Create hit particles
                        tempCollisionParticle = Instantiate(PlayerHitParticles, other.transform.position, other.transform.rotation) as ParticleSystem;
                        tempCollisionParticle.Play();
                        Destroy(tempCollisionParticle.gameObject, 2f);
                    }
                }
                // Return the needle to the player who threw the needle
                if (shooter != null && shooter.GetComponent <PlayerHealthAmmo>().currentAmmo < 4)
                {
                    shooter.GetComponent <PlayerHealthAmmo>().currentAmmo++;
                }
                // If the needle was generated by a box, give the needle to the player hit
                else if (playerHealthAmmo.currentAmmo < 4)
                {
                    playerHealthAmmo.currentAmmo++;
                }


                gameObject.SetActive(false);
                rb.isKinematic = false;
            }
            // Otherwise let the player pick up the needle
            else if (playerHealthAmmo.currentAmmo < 4)
            {
                playerHealthAmmo.currentAmmo++;
                gameObject.SetActive(false);
                rb.isKinematic   = false;
                transform.parent = null;
            }

            rb.velocity = Vector3.zero;
        }

        if (other.tag == "Box" && transform.parent == null)
        {
            rb.velocity      = Vector3.zero;
            transform.parent = other.transform;

            boxManager = other.GetComponent <BoxManager>();
            boxManager.BoxDamage(boxDamage);

            if (boxManager.isDestroyed)
            {
                other.gameObject.GetComponent <Collider>().enabled = false;

                foreach (Transform child in other.transform)
                {
                    child.gameObject.SetActive(false);
                    child.gameObject.GetComponent <Rigidbody>().isKinematic = false;
                }

                other.transform.DetachChildren();
                gameObject.SetActive(false);
                rb.isKinematic = false;

                // signal if current box has been hit and create explosion
                tempDeathParticle = Instantiate(BoxDeathParticles, other.transform.position, other.transform.rotation) as ParticleSystem;
                tempDeathParticle.Play();
                Destroy(tempDeathParticle.gameObject, 2f);
            }

            else
            {
                SoundManager.instance.RandomizeSfx(0.9f, boxHitSounds).Play();
                tempCollisionParticle = Instantiate(BoxHitParticles, transform.position, transform.rotation) as ParticleSystem;
                tempCollisionParticle.Play();
                Destroy(tempCollisionParticle.gameObject, 2f);
            }
        }

        if (other.tag == "Reflective" && transform.parent == null)
        {
            SoundManager.instance.RandomizeSfx(0.5f, needleRicochets).Play();
            Vector3 deflectDir = Vector3.Reflect(hitDir, other.transform.up);
            deflectDir.y      = 0;
            transform.forward = deflectDir;
            rb.velocity       = transform.forward * hitVel.magnitude;
        }

        if (other.tag == "WoolBall")
        {
            SoundManager.instance.PlaySingle(1f, needleHitWoolBall);
            rb.velocity      = Vector3.zero;
            transform.parent = other.transform;
        }
    }