- Home /
Progress bar UI
Hey everyone! I would like to make a bar shrink/enlarge as time passes. How is it possible to do?
To test: I have a GUI texture of specific size. I've written a script to change its size as a button is pressed, but it doesn't work. Could you help me please?
Here's the script:
using UnityEngine;
using System.Collections;
public class barscript : MonoBehaviour {
public GUITexture guii1;
// Use this for initialization
void Start () {
guii1 = GameObject.Find("_GUI Stuff/GUI0").GetComponent<GUITexture>();
}
// Update is called once per frame
void Update () {
if(Input.GetKeyUp(KeyCode.Space))
{
guii1.texture.height = guii1.texture.height +15;
}
}
error: "Exception: not implemented UnityEngine.Texture.set_height (Int32 value)..."
You are resizing the texture. You should resize the size of the plane/sprite/image object that the texture is on.
Answer by EggQuiz857 · Jan 01, 2015 at 05:14 AM
What I have done is animate a plain and stretch it. It might be the most simple way.
Answer by Fewpwew130 · Dec 28, 2014 at 01:27 PM
Thank you, can you tell me please how to resize the image then? :)
Yes I can. Image, as an UI component is added to a gameobject that also has RectTransform component. Through code you would change its size using:
transform.GetComponent<Rect>.Set(float left, float top, float width, float height);
I am very sorry, but I failed to understand. Let's try it super simple. I want to resize a 2d picture as UI element (not a plane, because it's a multiplayer game and other players would be able to see it in that case). For that purpose I created an Empty. I added Rect Transform component to it. Now how do I add image I want? I try to drag it over, but it doesn't allow to place it there.
I suggest you start with offical UI tutorials. By the time you finish lesson 4, you will understand this much better.
And don't get me wrong, but multiplayer games are too complicated to start with if you are having problems with this kind of stuff. Start with something simpler.
Your answer
![](https://koobas.hobune.stream/wayback/20220613175035im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Assigning UV Map to model at runtime 0 Answers
Mask a HP Bar 0 Answers
Invert Texture 0 Answers
Food bar help 1 Answer
Floating Health Bars 1 Answer