// Bullet hitting enemies
    void OnTriggerEnter2D(Collider2D hitInfo)
    {
        // Hit info on what enemies the bullet hits
        Rat  rat  = hitInfo.GetComponent <Rat>();
        Wolf wolf = hitInfo.GetComponent <Wolf>();
        Bear bear = hitInfo.GetComponent <Bear>();

        if (rat != null)
        {
            // Rat Death sounds
            PlayerSoundScript.PlaySound("RatDeath");
            // Rat takes damage from the shotgun bullet
            rat.TakeDamage(shotgundamage);
        }

        if (wolf != null)
        {
            // Wolf Death sounds
            PlayerSoundScript.PlaySound("DogBark");
            // Wolf takes damage from the shotgun bullet
            wolf.TakeDamage(shotgundamage);
        }

        if (bear != null)
        {
            // Boss Death sounds
            //PlayerSoundScript.PlaySound ("Growl");
            // boss takes damage from the shotgun bullet
            bear.TakeDamage(shotgundamage);
        }
        // When adequate damage is given to enemy they are destroyed
        Destroy(gameObject);
    }
    private void OnTriggerEnter2D(Collider2D other)
    {
        if (other.gameObject.CompareTag("EnergyPickup"))
        {
            // Plays the sound for power up
            PlayerSoundScript.PlaySound("EnergyPower");
            // Destroys the object once taken
            Destroy(other.gameObject);
            // Changes player speed
            playerJumpPower = 2000;
            // Changes the color of the player to signify the power up change
            GetComponent <SpriteRenderer>().color = Color.yellow;
            // Reset Player
            StartCoroutine(ResetPower());
        }

        if (other.gameObject.CompareTag("Axe"))
        {
            // Plays the sound for Weapon pickup
            PlayerSoundScript.PlaySound("WeaponEquip");
            // Destroys the object once taken
            Destroy(other.gameObject);
            // Changes player sprite
            renderer        = GetComponent <SpriteRenderer>();
            playerAxe       = Resources.Load <Sprite> ("MC-axe");
            renderer.sprite = playerAxe;
            //playerAnim.SetTrigger("AxeCollect");
        }

        if (other.gameObject.CompareTag("Checkpoint"))
        {
            // Plays the sound for Checkpoint
            PlayerSoundScript.PlaySound("CheckpointCP");
            // Destroys the object once taken
            Destroy(other.gameObject);
        }

        if (other.gameObject.CompareTag("Coins"))
        {
            // Plays the sound for Checkpoint
            PlayerSoundScript.PlaySound("Coin");
            // Destroys the object once taken
            Destroy(other.gameObject);
        }

        if (other.gameObject.CompareTag("Gun"))
        {
            // Plays the sound for Checkpoint
            PlayerSoundScript.PlaySound("Gun");
            //GetComponent<GameObject>();
            renderer        = GetComponent <SpriteRenderer>();
            playerGun       = Resources.Load <Sprite> ("MC-SHOGUN");
            renderer.sprite = playerGun;
            // Destroys the object once taken
            Destroy(other.gameObject);
        }
    }
 void OnCollisionEnter2D(Collision2D col)
 {
     if (col.transform.CompareTag("Player"))
     {
         // Plays death sound
         PlayerSoundScript.PlaySound("PlayerDeath");
         // moves player to spawnpoint when dead
         col.transform.position = spawnPoint.position;
     }
 }
Beispiel #4
0
 void Awake()
 {
     if (instance != null && instance != this)
     {
         Destroy(this.gameObject);
         return;
     }
     else
     {
         instance = this;
     }
     DontDestroyOnLoad(this.gameObject);
 }
    void PlayerMove()
    {
        //Controls
        moveX = Input.GetAxis("Horizontal");

        //PlayerSounds.PlaySound ("PlayerWalk");
        if (Input.GetButtonDown("Jump"))
        {
            if (isGrounded)
            {
                // Player Jumping sounds
                PlayerSoundScript.PlaySound("Playerjump");
                //Calling player jump
                Jump();
                canDoubleJump = true;
            }
            else
            {
                if (canDoubleJump)
                {
                    // Plays jump sound
                    PlayerSoundScript.PlaySound("Playerjump");
                    canDoubleJump = false;
                    GetComponent <Rigidbody2D>().velocity = new Vector2(GetComponent <Rigidbody2D>().velocity.x, 0);
                    GetComponent <Rigidbody2D>().AddForce(Vector2.up * playerJumpPower);
                }
            }
        }
        //Animation
        //Player Direction
        Vector3 playerScale = transform.localScale;

        // Player flip
        if (Input.GetAxis("Horizontal") < 0)
        {
            playerScale.x = -0.9f;
        }
        else if (Input.GetAxis("Horizontal") > 0)
        {
            playerScale.x = 0.9f;
        }
        transform.localScale = playerScale;

        //Physics
        gameObject.GetComponent <Rigidbody2D>().velocity = new Vector2(moveX * playerSpeed, gameObject.GetComponent <Rigidbody2D>().velocity.y);
    }
 // Die method when health is 0
 void Die()
 {
     PlayerSoundScript.PlaySound("Growl");
     Destroy(gameObject);
 }
Beispiel #7
0
    /******************************************************
    * MonoBehaviour methods, OnTriggerEnter
    ******************************************************/

    void OnTriggerEnter(Collider other)
    {
        PlayerSoundScript soundScript = other.gameObject.GetComponent <PlayerSoundScript>();

        if (soundScript != null)
        {
            soundScript.playGunShotSound();
        }

        if (!IsRegenerating)
        {
            // a collider with the PlayerScript can only collect the item
            PlayerScript player = other.GetComponent <PlayerScript>();

            if (player != null)
            {
                IsRegenerating = true;

                // do something here

                /*if(position==1){
                 * player.itemHeld = 27;//Random.Range(1,100);
                 * }
                 * else if(position==2){
                 *
                 * }*/
                float position = other.GetComponent <PlayerPositionScript>().raceposition;
                float HP       = other.GetComponent <PlayerScript>().HP;
                if (player.itemHeld == 0)
                {
                    if (position == 1)
                    {
                        if (HP < 50)
                        {
                            player.itemHeld = Random.Range(position1low[0], position1low.Length);
                        }
                        else
                        {
                            player.itemHeld = Random.Range(position1[0], position1.Length);
                        }
                    }
                    else if (position == 2)
                    {
                        if (HP < 50)
                        {
                            player.itemHeld = Random.Range(position2low[0], position2low.Length);
                        }
                        else
                        {
                            player.itemHeld = Random.Range(position2[0], position2.Length);
                        }
                    }
                    else if (position == 3 || position == 4)
                    {
                        player.itemHeld = Random.Range(1, 100);
                    }
                    else if (position == 5)
                    {
                        if (HP < 50)
                        {
                            player.itemHeld = Random.Range(position5low[0], position5low.Length);
                        }
                        else
                        {
                            player.itemHeld = Random.Range(position5[0], position5.Length);
                        }
                    }
                    else
                    {
                        if (HP < 50)
                        {
                            player.itemHeld = Random.Range(position6low[0], position6low.Length);
                        }
                        else
                        {
                            player.itemHeld = Random.Range(position6[0], position6.Length);
                        }
                    }
                }
            }
        }
    }
Beispiel #8
0
 // Shoot method
 void Shoot()
 {
     // gun sound
     PlayerSoundScript.PlaySound("Shotgun");
     Instantiate(bulletPrefab, firepoint.position, firepoint.rotation);
 }