Beispiel #1
0
    void OnTriggerEnter(Collider other)
    {
        //Check if it is the player
        if (other.tag == "Player")
        {
            playerStats      = other.GetComponent <StatsManager> ();
            playerShooting   = other.GetComponent <PlayerShooting> ();
            playerMovement   = other.GetComponent <PlayerMovement> ();
            playerPrefix     = other.name;
            playerAugSprite  = GameObject.Find(playerPrefix + "Aug");
            playerWeapSprite = GameObject.Find(playerPrefix + "Weap");
            if (other.name == "P1")
            {
                nextPickup = nextPickupP1;
            }
            else
            {
                nextPickup = nextPickupP2;
            }

            if (Time.time > nextPickup)
            {
                //Check which pickup it is and apply effects
                switch (powerupType)
                {
                // case "BeepAugment":
                //  Augment temp = new Augment ("Sounds/beep/beep_1");
                //  Debug.Log (temp);
                //  playerStats.SetAugment (temp);
                //  playerAugSprite.GetComponent<Image> ().sprite = Resources.Load<Sprite> ("SpeedUpSprite");

                //  Debug.Log (playerStats.GetAugment());

                //  break;
                // case "GrowAugment":
                //  GrowAugment g = new GrowAugment();
                //  Debug.Log (g);
                //  playerStats.SetAugment (g);
                //  playerAugSprite.GetComponent<Image> ().sprite = Resources.Load<Sprite> ("BulletSpeedUpSprite");

                //  Debug.Log (playerStats.GetAugment());

                //  break;
                case "FireAugment":
                    if (playerStats.GetAugment() != null)
                    {
                        oldAugment = playerStats.GetAugment().Element;
                    }
                    FireAugment f = new FireAugment();
                    Debug.Log(f);
                    playerStats.SetAugment(f);
                    playerAugSprite.GetComponent <Image> ().sprite = Resources.Load <Sprite> ("Interface/Augment-Red-Blank");
                    audioPlacement.PlayClip("AugmentPickUp", 1f);

                    Debug.Log(playerStats.GetAugment());

                    break;

                case "IceAugment":
                    if (playerStats.GetAugment() != null)
                    {
                        oldAugment = playerStats.GetAugment().Element;
                    }
                    IceAugment i = new IceAugment();
                    Debug.Log(i);
                    playerStats.SetAugment(i);
                    playerAugSprite.GetComponent <Image> ().sprite = Resources.Load <Sprite> ("Interface/Augment-Blue-Blank");
                    audioPlacement.PlayClip("AugmentPickUp", 1f);

                    Debug.Log(playerStats.GetAugment());

                    break;

                case "EarthAugment":
                    if (playerStats.GetAugment() != null)
                    {
                        oldAugment = playerStats.GetAugment().Element;
                    }
                    EarthAugment e = new EarthAugment();
                    Debug.Log(e);
                    playerStats.SetAugment(e);
                    playerAugSprite.GetComponent <Image> ().sprite = Resources.Load <Sprite> ("Interface/Augment-Green-Blank");
                    audioPlacement.PlayClip("AugmentPickUp", 1f);

                    Debug.Log(playerStats.GetAugment());

                    break;

                case "Pistol":
                    oldWeapon = playerShooting.curWeap;
                    playerShooting.ChangeWeapon(powerupType);
                    audioPlacement.PlayClip("WeaponPickUp", 1f);
                    break;

                case "RayGun":
                    oldWeapon = playerShooting.curWeap;
                    playerShooting.ChangeWeapon(powerupType);
                    //playerWeapSprite.GetComponent<Image> ().sprite = Resources.Load<Sprite> ("raygunsprite");
                    audioPlacement.PlayClip("WeaponPickUp", 1f);
                    break;

                case "Sword":
                    oldWeapon = playerShooting.curWeap;
                    playerShooting.ChangeWeapon(powerupType);
                    //playerWeapSprite.GetComponent<Image> ().sprite = Resources.Load<Sprite> ("swordsprite");
                    audioPlacement.PlayClip("WeaponPickUp", 1f);
                    break;

                case "FullHealth":
                    if (HealthManager.currentHealth < 10)
                    {
                        HealthManager.HealHealth(2);
                        audioPlacement.PlayClip("ItemPickUp", 1f);
                    }
                    else
                    {
                        notUsed = true;
                    }
                    break;

                case "HalfHealth":
                    if (HealthManager.currentHealth < 10)
                    {
                        HealthManager.HealHealth(1);
                        audioPlacement.PlayClip("ItemPickUp", 1f);
                    }
                    else
                    {
                        notUsed = true;
                    }
                    break;
                }

                if (oldWeapon != null)
                {
                    if (oldWeapon == "Pistol")
                    {
                        oldWeaponPickup = Instantiate(pistolPickup, transform.position, pistolPickup.transform.rotation) as GameObject;
                    }
                    else if (oldWeapon == "RayGun")
                    {
                        oldWeaponPickup = Instantiate(rayGunPickup, transform.position, rayGunPickup.transform.rotation) as GameObject;
                    }
                    else if (oldWeapon == "Sword")
                    {
                        oldWeaponPickup = Instantiate(swordPickup, transform.position, swordPickup.transform.rotation) as GameObject;
                    }

                    oldWeaponPickup.transform.parent = playerStats.RoomIn.transform;
                    oldWeapon = null;
                }

                if (oldAugment != null)
                {
                    if (oldAugment == "fire")
                    {
                        oldAugmentPickup = Instantiate(redAugmentPickup, transform.position, redAugmentPickup.transform.rotation) as GameObject;
                    }
                    else if (oldAugment == "ice")
                    {
                        oldAugmentPickup = Instantiate(blueAugmentPickup, transform.position, blueAugmentPickup.transform.rotation) as GameObject;
                    }
                    else if (oldAugment == "earth")
                    {
                        oldAugmentPickup = Instantiate(greenAugmentPickup, transform.position, greenAugmentPickup.transform.rotation) as GameObject;
                    }

                    oldAugmentPickup.transform.parent = playerStats.RoomIn.transform;
                    oldAugment = null;
                }

                //Get rid of the pickup if it has been used
                if (!notUsed)
                {
                    Destroy(gameObject);
                }

                //Reset the variable for next switch statement
                notUsed = false;

                //Check if P1 or P2 picked it up, update nextPickup time respectively
                if (other.name == "P1")
                {
                    nextPickupP1 = Time.time + 1f;
                }
                else
                {
                    nextPickupP2 = Time.time + 1f;
                }
            }
        }
    }
Beispiel #2
0
	void OnTriggerEnter(Collider other) {

		//Check if it is the player
		if (other.tag == "Player") {
			playerStats = other.GetComponent<StatsManager> ();
			playerShooting = other.GetComponent<PlayerShooting> ();
			playerMovement = other.GetComponent<PlayerMovement> ();
			playerPrefix = other.name;
			playerAugSprite = GameObject.Find (playerPrefix + "Aug");
			playerWeapSprite = GameObject.Find (playerPrefix + "Weap");
			if (other.name == "P1") {
				nextPickup = nextPickupP1;
			} else {
				nextPickup = nextPickupP2;
			}

			if (Time.time > nextPickup) {

				//Check which pickup it is and apply effects
				switch (powerupType) 
				{
				// case "BeepAugment":
				// 	Augment temp = new Augment ("Sounds/beep/beep_1");
				// 	Debug.Log (temp);
				// 	playerStats.SetAugment (temp);
				// 	playerAugSprite.GetComponent<Image> ().sprite = Resources.Load<Sprite> ("SpeedUpSprite");

				// 	Debug.Log (playerStats.GetAugment());

				// 	break;
				// case "GrowAugment":
				// 	GrowAugment g = new GrowAugment();
				// 	Debug.Log (g);
				// 	playerStats.SetAugment (g);
				// 	playerAugSprite.GetComponent<Image> ().sprite = Resources.Load<Sprite> ("BulletSpeedUpSprite");

				// 	Debug.Log (playerStats.GetAugment());

				// 	break;
				case "FireAugment":
					if (playerStats.GetAugment() != null) {
						oldAugment = playerStats.GetAugment().Element;
					}
					FireAugment f = new FireAugment();
					Debug.Log (f);
					playerStats.SetAugment (f);
					playerAugSprite.GetComponent<Image> ().sprite = Resources.Load<Sprite> ("Interface/Augment-Red-Blank");
					audioPlacement.PlayClip("AugmentPickUp", 1f);

					Debug.Log (playerStats.GetAugment());

					break;
				case "IceAugment":
					if (playerStats.GetAugment() != null) {
						oldAugment = playerStats.GetAugment().Element;
					}
					IceAugment i = new IceAugment();
					Debug.Log (i);
					playerStats.SetAugment (i);
					playerAugSprite.GetComponent<Image> ().sprite = Resources.Load<Sprite> ("Interface/Augment-Blue-Blank");
					audioPlacement.PlayClip("AugmentPickUp", 1f);

					Debug.Log (playerStats.GetAugment());

					break;
				case "EarthAugment":
					if (playerStats.GetAugment() != null) {
						oldAugment = playerStats.GetAugment().Element;
					}
					EarthAugment e = new EarthAugment ();
					Debug.Log (e);
					playerStats.SetAugment (e);
					playerAugSprite.GetComponent<Image> ().sprite = Resources.Load<Sprite> ("Interface/Augment-Green-Blank");
					audioPlacement.PlayClip("AugmentPickUp", 1f);

					Debug.Log (playerStats.GetAugment ());

					break;

				case "Pistol":
					oldWeapon = playerShooting.curWeap;
					playerShooting.ChangeWeapon(powerupType);
					audioPlacement.PlayClip("WeaponPickUp", 1f);
					break;

				case "RayGun":
					oldWeapon = playerShooting.curWeap;
					playerShooting.ChangeWeapon(powerupType);
					//playerWeapSprite.GetComponent<Image> ().sprite = Resources.Load<Sprite> ("raygunsprite");
					audioPlacement.PlayClip("WeaponPickUp", 1f);
					break;

				case "Sword":
					oldWeapon = playerShooting.curWeap;
					playerShooting.ChangeWeapon (powerupType);
					//playerWeapSprite.GetComponent<Image> ().sprite = Resources.Load<Sprite> ("swordsprite");
					audioPlacement.PlayClip("WeaponPickUp", 1f);
					break;

				case "FullHealth":
					if (HealthManager.currentHealth < 10) {
						HealthManager.HealHealth (2);
						audioPlacement.PlayClip("ItemPickUp", 1f);
					} else {
						notUsed = true;
					}
					break;
				
				case "HalfHealth":
					if (HealthManager.currentHealth < 10) {
						HealthManager.HealHealth (1);
						audioPlacement.PlayClip("ItemPickUp", 1f);
					} else {
						notUsed = true;
					}
					break;
				}

				if (oldWeapon != null) {
					if (oldWeapon == "Pistol") {
						oldWeaponPickup = Instantiate (pistolPickup, transform.position, pistolPickup.transform.rotation) as GameObject;
					} else if (oldWeapon == "RayGun") {
						oldWeaponPickup = Instantiate (rayGunPickup, transform.position, rayGunPickup.transform.rotation) as GameObject;
					} else if (oldWeapon == "Sword") {
						oldWeaponPickup = Instantiate (swordPickup, transform.position, swordPickup.transform.rotation) as GameObject;
					}

					oldWeaponPickup.transform.parent = playerStats.RoomIn.transform;
					oldWeapon = null;
				}

				if (oldAugment != null) {
					if (oldAugment == "fire") {
						oldAugmentPickup = Instantiate (redAugmentPickup, transform.position, redAugmentPickup.transform.rotation) as GameObject;
					} else if (oldAugment == "ice") {
						oldAugmentPickup = Instantiate (blueAugmentPickup, transform.position, blueAugmentPickup.transform.rotation) as GameObject;
					} else if (oldAugment == "earth") {
						oldAugmentPickup = Instantiate (greenAugmentPickup, transform.position, greenAugmentPickup.transform.rotation) as GameObject;
					}

					oldAugmentPickup.transform.parent = playerStats.RoomIn.transform;
					oldAugment = null;
				}

				//Get rid of the pickup if it has been used
				if (!notUsed){
					Destroy (gameObject);
				}
				
				//Reset the variable for next switch statement
				notUsed = false;

				//Check if P1 or P2 picked it up, update nextPickup time respectively
				if (other.name == "P1") {
					nextPickupP1 = Time.time + 1f;
				} else {
					nextPickupP2 = Time.time + 1f;
				}
			}
		}
	}