Ejemplo n.º 1
0
    PlatformCalledAlert SpawnHealthChangedAlert(int difference)
    {
        if (difference == 0)
        {
            return(null);
        }
        if (RegainedHealthPrefab == null)
        {
            // This is the first one to be spawned, so find the prefab
            RegainedHealthPrefab = Resources.Load("RegainedHealthAlert") as GameObject;
        }
        if (LostHealthPrefab == null)
        {
            // This is the first one to be spawned, so find the prefab
            LostHealthPrefab = Resources.Load("LostHealthAlert") as GameObject;
        }
        GameObject healthAlertObject = GameObject.Instantiate(difference > 0 ? RegainedHealthPrefab : LostHealthPrefab,
                                                              owner.GetCharacter().transform.position + (Vector3)HEALTH_ALERT_OFFSET,
                                                              Quaternion.identity);

        // And set this parasite as it's parent in the hierarchy
        healthAlertObject.transform.SetParent(owner.GetCharacter().transform);
        PlatformCalledAlert healthAlert = healthAlertObject.GetComponentInChildren <PlatformCalledAlert>();

        // Show a '+' if the parasite is regaining health
        healthAlertObject.GetComponentInChildren <Text>().text = (difference > 0 ? "+" : "") + difference + " HP";
        return(healthAlert);
    }
Ejemplo n.º 2
0
 void OnHealthChanged(int difference)
 {
     if (difference > 0)
     {
         SpawnHealthChangedAlert(difference);
     }
     else if (difference < 0)
     {
         if (lostHealthAlert == null)
         {
             lostHealthAlert      = SpawnHealthChangedAlert(difference);
             lostHealthAlertValue = difference;
         }
         else
         {
             lostHealthAlertValue += difference;
             lostHealthAlert.SetText((lostHealthAlertValue) + " HP");
             lostHealthAlert.Restart();
         }
     }
 }