Beispiel #1
0
        void Update()
        {
            _points = PointsController.GetPoints();
            if (_pointsObj != null)
            {
                _pointsObj.GetComponent <Text>().text = _points.ToString();
            }

            _lifes = LifesController.GetLifes();

            /*if (_lifesObj != null)
             * {
             *  _lifesObj.GetComponent<UILabel>().text = _lifes.ToString();
             * }*/

            for (int i = 0; i < _listOfLifes.Count(); i++)
            {
                //_listOfLifes[i].transform.localPosition = new Vector3(Screen.width * 2 - (_listOfLifes[i].GetComponent<UI2DSprite>().width * i) - _offSetX * i, (Screen.height * 2 - _listOfLifes[i].GetComponent<UI2DSprite>().height / 2f));
                if (LifesController.GetLifes() > 0)
                {
                    for (int k = LifesController.GetLifes(); k < LifesController.GetInitialLifes(); k++)
                    {
                        _listOfLifes[k].GetComponent <Image>().sprite = Resources.Load <Sprite>(PathConstants.GetGameScenePath() + "lifeIcon_empty");
                    }
                }
            }
        }
Beispiel #2
0
        public void CreateLifeHud()
        {
            _listOfLifes = new List <GameObject>();

            /*_lifeHUD = new GameObject();
             * _lifeHUD.name = "lifeHud";
             * _lifeHUD.transform.parent = this.gameObject.transform;*/

            for (int i = 0; i < LifesController.GetInitialLifes(); i++)
            {
                GameObject _life = new GameObject();
                _life.transform.parent = _canvas.transform;
                _life.name             = "life" + i;
                _life.AddComponent <CanvasRenderer>();
                _life.AddComponent <Image>().sprite         = Resources.Load <Sprite>(PathConstants.GetGameScenePath() + "lifeIcon_full");
                _life.GetComponent <Image>().preserveAspect = true;
                _listOfLifes.Add(_life);

                float lifeWidth = _life.GetComponent <Image>().sprite.bounds.size.x * 100f;

                Debug.Log("lifeWidth: " + lifeWidth);

                _life.GetComponent <RectTransform>().anchorMin        = _anchorMin;
                _life.GetComponent <RectTransform>().anchorMax        = _anchorMax;
                _life.GetComponent <RectTransform>().anchoredPosition = new Vector2(_lifeHUD.GetComponent <RectTransform>().anchoredPosition.x + _lifeHUD.GetComponent <Text>().preferredWidth + lifeWidth * i + (_offSetX * i), _lifeHUD.GetComponent <RectTransform>().anchoredPosition.y);

                /*_life.GetComponent<UI2DSprite>().SetAnchor(this.gameObject);
                 * _life.GetComponent<UI2DSprite>().topAnchor.absolute = 817;
                 * _life.GetComponent<UI2DSprite>().bottomAnchor.absolute = 528;
                 * _life.GetComponent<UI2DSprite>().leftAnchor.absolute = 622 - lifeWidth * i - (_offSetX * i);
                 * _life.GetComponent<UI2DSprite>().rightAnchor.absolute = 1320 - lifeWidth * i - (_offSetX * i);
                 * _life.GetComponent<UI2DSprite>().UpdateAnchors();
                 * _life.GetComponent<UI2DSprite>().MakePixelPerfect();
                 * FindObjectOfType<IndexController>().AddObjectToLIstByIndex(_life, 4);*/
            }
        }