Esempio n. 1
0
    void Start()
    {
        body = GetComponent <Rigidbody2D>();
        Transform hpBarObject = transform.Find("HPBar");

        if (hpBarObject)
        {
            hpBar = hpBarObject.GetComponent <UI_Healthbar>();
            Debug.LogFormat("{0} --> {1}", name, hpBar);
        }
        hp = maxHp;
        Debug.Assert(body);
    }
Esempio n. 2
0
    // Update train UI stuff, like train healthbars
    public void UpdateTrainInfo(Train train)
    {
        // Delete all healthbars
        foreach (Transform child in bottom.transform)
        {
            Destroy(child.gameObject);
        }
        // Add healthbars for all train cars
        int   ncars    = train.cars.Count;
        int   n        = 0;
        float leftSide = (ncars * 120.0f) / 2.0f;

        foreach (TrainCar car in train.cars)
        {
            GameObject   newHPBar    = Instantiate(hpBarPrefab, bottom.transform);
            UI_Healthbar uiHealthBar = newHPBar.GetComponent <UI_Healthbar>();
            uiHealthBar.who = car.GetComponent <Attackable>();
            newHPBar.SetActive(true);
            newHPBar.transform.localPosition = new Vector2(n * 120.0f - leftSide, 0);
            n += 1;
        }
        Debug.Log("Updated train UI info");
    }