Example #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);
        }
    }
Example #2
0
 private void Start()
 {
     rightFingerId         = -1;
     sceneController       = GameObject.FindGameObjectWithTag("SceneController").GetComponent <SceneControll>();
     shootingButtonPressed = false;
     meleeScript           = GetComponentInChildren <MeleeAttack>();
     ammoHealthScript      = GetComponent <PlayerHealthAmmo>();
     camDistance           = mainCamera.transform.localPosition.z;
     cameraCam             = mainCamera.GetComponent <Camera>();
     startCamPos           = mainCamera.transform.localPosition;
     startFOV   = cameraCam.fieldOfView;
     crossImage = cross.GetComponent <Image>();
     aiming     = false;
     nonAimingButton.SetActive(false);
     shootingButton.SetActive(false);
     controller      = GetComponent <CharacterController>();
     animator        = player.GetComponent <Animator>();
     startCrossColor = crossImage.color;
     reloadImgItself = reloadImg.GetComponent <Image>();
     reloadImg.SetActive(false);
     meleeObject.SetActive(false);
     shootingAudioSource = shootPoint.GetComponent <AudioSource>();
     tanyaSoundSource    = GetComponent <AudioSource>();
     startStepPos        = transform.position;
     shootlight          = shootPoint.GetComponent <Light>();
     shootlight.enabled  = false;
     startIntensity      = shootlight.intensity;
     //flashlight = shootPoint.transform.GetChild(0).gameObject.GetComponent<Light>();
     //flashlight.cookie = lightCookie;
 }
 private void OnTriggerEnter(Collider other)
 {
     if (other.gameObject.tag == "Player" & !damaged)
     {
         PlayerHealthAmmo playerScript = other.gameObject.GetComponent <PlayerHealthAmmo>();
         damaged = true;
         playerScript.TakeDamage(Random.Range(5f, 15f));
     }
 }
Example #4
0
 private void Start()
 {
     controllScript  = GetComponent <TanyaRifleControll>();
     reloadImgItself = reloadImg.GetComponent <Image>();
     crossImgItself  = aimingCross.GetComponent <Image>();
     crossColor      = crossImgItself.color;
     meleeScript     = GetComponentInChildren <MeleeAttack>();
     ammoScript      = GetComponent <PlayerHealthAmmo>();
     reloadImg.SetActive(false);
     meleeObject.SetActive(false);
 }
Example #5
0
    private void OnEnable()
    {
        // When the player is spawned, make sure it's not kinematic.
        player.isKinematic = false;
        // Set the power-up flags to inactive
        helmActive   = false;
        shieldActive = false;
        // Set the collision flag to false
        isHit = false;

        playerHealthAmmo = GetComponent <PlayerHealthAmmo>();
    }
Example #6
0
 private void OnTriggerEnter(Collider other)
 {
     if (other.gameObject.tag == "Player")
     {
         PlayerHealthAmmo ammoScript = other.gameObject.GetComponent <PlayerHealthAmmo>();
         if (ammoScript.ammo != ammoScript.maxAmmo)
         {
             ammoScript.AddAmmo(Random.Range(minAmmo, maxAmmo));
         }
         GameObject effect = ammoEffect;
         Instantiate(effect, other.gameObject.transform.position + Vector3.up * 0.7f, Quaternion.identity, other.gameObject.transform);
         //sceneController.ammoInGame.Remove(this.gameObject);
         DestroyLoot();
     }
 }
Example #7
0
 //void Awake()
 void Start()
 {
     soundTimer  = Random.Range(1f, 8f);
     zombieSound = GetComponent <AudioSource>();
     dead        = false;
     agent       = GetComponent <NavMeshAgent>();
     zombie      = transform.GetChild(0).transform.GetChild(1).gameObject;
     mat         = zombie.GetComponent <Renderer>().material;
     animator    = transform.GetChild(0).GetComponent <Animator>();
     startCol    = mat.color;
     startHealth = health;
     animator.SetFloat("cycleOffset", Random.Range(0f, 1f));
     localSceneController = GameObject.FindGameObjectWithTag("SceneController").GetComponent <SceneControll>();
     //player = GameObject.FindGameObjectWithTag("Player");
     player       = localSceneController.player;
     playerScript = player.GetComponent <PlayerHealthAmmo>();
     captureSpot.GetComponent <CapturePoint>().zombiesInGame.Add(this.gameObject);
 }
Example #8
0
    private void OnTriggerEnter(Collider other)
    {
        if (other.gameObject.tag == "Player")
        {
            PlayerHealthAmmo healthScript = other.gameObject.GetComponent <PlayerHealthAmmo>();

            if (healthScript.playerHealth != healthScript.maxPlayerHealth)
            {
                healthScript.Heal(Random.Range(minHeal, maxHeal));
                GameObject effect = healEffect;
                Instantiate(effect, other.gameObject.transform.position, Quaternion.identity, other.gameObject.transform);
                DestroyLoot();
            }
            else
            {
                healthScript.Heal(0);
            }
        }
    }
Example #9
0
 private void OnTriggerEnter(Collider other)
 {
     if (other.gameObject.tag == "Player" & timer == 0f)
     {
         SaveSystem.SavePlayer(sceneController);
         PlayerControll   controllScript   = other.gameObject.GetComponent <PlayerControll>();
         PlayerHealthAmmo healthAmmoScript = other.gameObject.GetComponent <PlayerHealthAmmo>();
         sceneController.savedAmmo      = healthAmmoScript.ammo;
         sceneController.savedShot      = controllScript.shot;
         sceneController.savedHealth    = healthAmmoScript.playerHealth;
         sceneController.savedPlayerPos = other.transform.position;
         sceneController.fromStart      = false;
         //sceneController.killedInGame =
         timer = timerReload;
         //saveIcon = other.gameObject.
         saveIconUI = controllScript.saveIcon;
         StartCoroutine(SaveIconVisible());
         saveIcon.SetActive(false);
     }
 }
Example #10
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;
            }
        }
    }
Example #11
0
 //void Awake()
 void Start()
 {
     LoadData();
     if (!inMenu)
     {
         currentSceneIndex = SceneManager.GetActiveScene().buildIndex;
         paused            = false;
         GameObject       playerToSpawn = playerPrefab;
         PlayerControll   controllP     = playerToSpawn.GetComponent <PlayerControll>();
         PlayerHealthAmmo controllHA    = playerToSpawn.GetComponent <PlayerHealthAmmo>();
         died = false;
         if (fromStart)
         {
             killedInGame            = 0;
             controllP.shot          = 0;
             controllHA.playerHealth = controllHA.maxPlayerHealth;
             controllHA.ammo         = startAmmo;
             Instantiate(playerToSpawn, startplayerPos + Vector3.up * 0.1f, Quaternion.identity);
         }
         else
         {
             killedInGame            = savedKilledInGame;
             controllP.shot          = savedShot;
             controllHA.playerHealth = savedHealth;
             controllHA.ammo         = savedAmmo;
             Instantiate(playerToSpawn, savedPlayerPos + Vector3.up * 0.1f, Quaternion.identity);
         }
         UnPause();
         player       = GameObject.FindGameObjectWithTag("Player");
         capturePoint = GameObject.FindGameObjectsWithTag("Capturepoint");
     }
     else
     {
         savedAmmo      = startAmmo;
         savedHealth    = 100f;
         savedShot      = 0;
         savedPlayerPos = Vector3.zero;
     }
 }
Example #12
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;
        }
    }