Beispiel #1
0
    public void UseItem()
    {
        PotionSelector.PotionElement selected = PotionSelector.GetSelectedPotionElement();

        //currentItem ist momentan leer, aber neues, verfuegbares potion ist ausgewaehlt
        if (currentItem == null && selected.GetCount() > 0)
        {
            currentItem = Instantiate(selected.prefab, hand.position, Quaternion.identity, hand).GetComponent <Potion>();
        }

        //currentItem ist vorhanden
        if (currentItem != null)
        {
            //currentItem wurde noch nicht geworfen und es wurde ein neues potion gewaehlt
            if (!currentItem.HasBeenThrown() && PotionSelector.GetSelectedPotionType() != currentItem.type)
            {
                //momentan ausgewaehltes zerstoeren
                Destroy(currentItem.gameObject);
                currentItem = null;
                //falls neues ausgewaehltes verfuegbar, erstellen
                if (selected.GetCount() > 0)
                {
                    currentItem = Instantiate(selected.prefab, hand.position, Quaternion.identity, hand).GetComponent <Potion>();
                }
            }

            //falls mausklick, currentItem vorhanden und momentanes currentItem noch nicht geworfen...
            if (input.isFiring && currentItem != null && !currentItem.HasBeenThrown())
            {
                ThrowPotion();                                       //werfen
                StartCoroutine(RespawnPotionCoroutine(currentItem)); //respawnroutine starten
            }
        }
    }
Beispiel #2
0
    IEnumerator RespawnPotionCoroutine(Potion thrownPotion)
    {
        yield return(new WaitForSeconds(0.2f)); //cooldown

        PotionSelector.PotionElement selected = PotionSelector.GetSelectedPotionElement();
        //wenn currentItem==null ist das potion wahrscheinlich schon geplatzt, ersetzen in UseItem()
        //wenn currentItem vorhanden
        if (currentItem != null)
        {
            //geworfenen Potion ist noch im flug
            if (currentItem == thrownPotion)
            {
                if (selected.GetCount() > 0)
                {
                    currentItem = Instantiate(selected.prefab, hand.position, Quaternion.identity, hand).GetComponent <Potion>();
                }
            }
        }
    }
Beispiel #3
0
 public static void SubtractFromCountOfPotion(Potion.Type t, int i)
 {
     PotionSelector.PotionElement pe = PotionSelector.GetPotionElementOfType(t);
     pe.SetCount(pe.GetCount() - i);
 }
Beispiel #4
0
 public static void AddToCountOfPotion(Potion.Type t, int i)
 {
     PotionSelector.PotionElement pe = PotionSelector.GetPotionElementOfType(t);
     pe.SetCount(pe.GetCount() + i);
 }
Beispiel #5
0
 public static int GetPotionAmount(Potion.Type t)
 {
     PotionSelector.PotionElement pe = PotionSelector.GetPotionElementOfType(t);
     return(pe.GetCount());
 }