W
W
WalloutDay2015-12-20 11:37:26
Game development
WalloutDay, 2015-12-20 11:37:26

UNITY NGUI Sprite fill amount?

41031a6cb68243cfaece9dc59d98bb7b.png
Faced a problem. How to influence the fill amount from NGUI through a script. The script hung on the player. He must be responsible for health. Everything is working. But when it comes to the visual part, I can’t influence the sprite in any way. Help! How to influence him!?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Daniil Basmanov, 2015-12-21
@WalloutDay

Get a reference to the UISprite component and change its fillAmount parameter. Like this:

using UnityEngine;

public class Test : MonoBehaviour
{
    public UISprite healthSprite;

    private void Awake()
    {
        healthSprite.fillAmount = 1;
    }

    private void Update()
    {
        healthSprite.fillAmount -= 0.01f;
    }
}

Hang the script above on some object, drag the sprite to the healthSprite field in the inspector and you're done.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question