void OnTriggerEnter(Collider collided)
        {
            switch (collided.gameObject.tag)
            {
            case "EnemyBullet":
                Debug.Log(" in EnemyBullet2 --------------------");
                playerHealth.TakeDamage(1);
                SoundManagerScript.PlayOneShot("damage1");
                Debug.Log(playerHealth.currentHealth);
                break;

            case "Bullet":
                Debug.Log(" in Bullet2 --------------------");
                playerHealth.TakeDamage(1);
                SoundManagerScript.PlayOneShot("damage1");
                Debug.Log(playerHealth.currentHealth);
                break;

            case "Health":
                playerHealth.Add(1);
                playerHealthSlider.Add(1);
                Destroy(collided.gameObject);
                break;

            case "Ammo":

                WeaponController.AddAmmo(20);
                ammoSlider.Set(WeaponController.GetAmmo());
                Destroy(collided.gameObject);
                break;

            case "FlameFuelTank":
                inventory.AddItem(collided.gameObject);
                collided.gameObject.SetActive(false);
                break;

            case "TeslaCoil":
                inventory.AddItem(collided.gameObject);
                collided.gameObject.SetActive(false);
                break;

            case "AcidFuelTank":
                inventory.AddItem(collided.gameObject);
                collided.gameObject.SetActive(false);
                break;

            case "Igniter":
                inventory.AddItem(collided.gameObject);
                collided.gameObject.SetActive(false);
                break;

            case "BatteryPack":
                inventory.AddItem(collided.gameObject);
                collided.gameObject.SetActive(false);
                break;

            default:
                break;
            }
        }
Example #2
0
    void UpdateValue()
    {
        Debug.LogFormat("Updating value of diffSlider to {0}", diffSlider.value);

        if (diffSlider.value == 1)
        {
            SoundManagerScript.PlayOneShot("Kid_Laugh");
        }
        else if (diffSlider.value == 2)
        {
            SoundManagerScript.PlayOneShot("Laughter");
        }
        else if (diffSlider.value == 3)
        {
            SoundManagerScript.PlayOneShot("Maniac");
        }
    }
        void OnParticleCollision(GameObject other)
        {
            switch (other.gameObject.tag)
            {
            case "EnemyBullet":
                Debug.Log(" in EnemyBullet2 --------------------");
                playerHealth.TakeDamage(1);
                SoundManagerScript.PlayOneShot("damage1");
                Debug.Log(playerHealth.currentHealth);
                break;

            case "Bullet":
                Debug.Log(" in Bullet2 --------------------");
                playerHealth.TakeDamage(1);
                SoundManagerScript.PlayOneShot("damage1");
                Debug.Log(playerHealth.currentHealth);
                break;

            default:
                break;
            }
        }
        void OnCollisionEnter(Collision collision)
        {
            switch (collision.gameObject.tag)
            {
            case "EnemyBullet":
                Debug.Log(" in EnemyBullet --------------------");
                SoundManagerScript.PlayOneShot("damage1");
                playerHealth.TakeDamage(1);
                Debug.Log(playerHealth.currentHealth);
                break;

            case "Bullet":
                Debug.Log(" in Bullet --------------------");
                SoundManagerScript.PlayOneShot("damage1");
                playerHealth.TakeDamage(1);
                Debug.Log(playerHealth.currentHealth);
                break;

            default:
                break;
            }
        }
Example #5
0
    public static void Increase(int amount)
    {
        SoundManagerScript.PlayOneShot("coin");
        Debug.LogFormat("Increasing score by {0}", amount);

        int score = int.Parse(scoreCounter.GetComponentInChildren <Text>().text);

        score += amount;

        scoreCounter.GetComponentInChildren <Text>().text = score.ToString();

        int highestScore = int.Parse(highestScoreCounter.GetComponentInChildren <Text>().text);

        if (score > highestScore)
        {
            Debug.LogFormat("New Highest Score ! {0}", score);

            PlayerPrefs.SetInt("highscore", score);

            highestScoreCounter.GetComponentInChildren <Text>().text = score.ToString();
        }
    }
        // Update is called once per frame
        void Update()
        {
            ammoSlider.Set(WeaponController.GetAmmo());

            Vector3 forward = cam.transform.forward;

            forward.y = 0;
            forward   = forward.normalized;
            Vector3    right          = new Vector3(forward.z, 0, -forward.x);
            float      horizontalAxis = Input.GetAxis("Horizontal");
            float      verticalAxis   = Input.GetAxis("Vertical");
            Quaternion rotation       = Quaternion.AngleAxis(10 * Mathf.Abs(horizontalAxis) * moveSpeed * Time.deltaTime, Vector3.up);

            //move = (horizontalAxis * right) + (verticalAxis * forward);

            //animate.SetBool("isGrounded", cont.isGrounded);
            float ydir = move.y;

            move   = (forward * verticalAxis) + (right * horizontalAxis);
            move   = rotation * move;
            move   = move.normalized * moveSpeed;
            move.y = ydir;

            if (wasJumpPressed)
            {
                timecounter += (Time.deltaTime);
                if (timecounter > delayJumpTime && !jumpExecuted)
                {
                    move.y       = jumpForce;
                    jumpExecuted = true;
                }
            }

            if (jumpExecuted && cont.isGrounded && timecounter > delayJumpTime + .5f)
            {
                // player has jumped and landed
                wasJumpPressed = false;
                jumpExecuted   = false;
                animate.SetBool("wasJumpPressed", false);
                timecounter = 0.0f;
            }

            if (Input.GetButtonDown("Jump") && cont.isGrounded)
            {
                if (!move.Equals(cont.isGrounded))
                {
                    // audio SFX
                    SoundManagerScript.PlayOneShot("jump");
                }



                animate.SetBool("wasJumpPressed", true);
                wasJumpPressed = true;

                // move.y = jumpForce;
            }


            move.y += Physics.gravity.y * gravityScale;



            if (Mathf.Abs(verticalAxis) + Mathf.Abs(horizontalAxis) > 0.1f)
            {
                animate.SetBool("isRunning", true);
            }
            else
            {
                animate.SetBool("isRunning", false);
            }

            if (wasAttackButtonPressed)
            {
                attackTimeCounter += (Time.deltaTime);
                if (attackTimeCounter > delayAttackTime)
                {
                    FireWeapon();
                }
            }

            if (Input.GetKeyDown(KeyCode.Alpha1) && !wasAttackButtonPressed)
            {
                WeaponController.SetActiveWeaponMode("standard");
            }
            if (Input.GetKeyDown(KeyCode.Alpha2) && !wasAttackButtonPressed)
            {
                WeaponController.SetActiveWeaponMode("Flames");
            }
            if (Input.GetKeyDown(KeyCode.Alpha3) && !wasAttackButtonPressed)
            {
                WeaponController.SetActiveWeaponMode("AcidSpray");
            }
            if (Input.GetKeyDown(KeyCode.Alpha4) && !wasAttackButtonPressed)
            {
                WeaponController.SetActiveWeaponMode("Lightning");
            }

            if (Input.GetButtonDown("Fire1") && !isPaused && !wasAttackButtonPressed && WeaponController.GetAmmoAvaliable() > 0)
            {
                animate.SetBool("isAttacking", true);
                wasAttackButtonPressed = true;
            }

            if (WeaponController.GetAmmoAvaliable() <= 0)
            {
                stopFireWeapon();
            }

            if (Input.GetButtonUp("Fire1"))
            {
                stopFireWeapon();
                animate.SetBool("isAttacking", false);
                attackTimeCounter      = 0;
                wasAttackButtonPressed = false;
            }

            cont.Move(move * Time.deltaTime);
            //transform.Rotate(rotation.eulerAngles);

            transform.rotation = Quaternion.LookRotation(Vector3.RotateTowards(transform.forward, new Vector3(move.x, 0f, move.z), moveSpeed * rotateSpeed * Time.deltaTime, 0f));

            animate.SetFloat("playerLife", playerHealth.currentHealth);

            if (transform.position.y <= -100)
            {
                respawn();
            }
        }