- Home /
Want to create a moving line over a filling object
Hello!
I am new to unity and am trying to create a simple moving progress bar. I have created the progress bar that moves up and down by vertical filling. However, I want to add a black line over the moving filled area (so it matches the border, see images). Is there an easy way to make the black horizontal line move with the other object as it fills (right now the black line is just a stationary object).
Thanks! Anna

Answer by unity_MXGApNcapNfNLg · May 18, 2021 at 11:32 AM
@AnnaVicVic Attach this script to the moving line and make moving line child of the surface (the surface will be a fill image)
using UnityEngine;
using UnityEngine.UI;
public class MoveableLine : MonoBehaviour
{
public Image fillImage;
public float rectHeight
public float incrementFactor;
void Update ()
{
var fillImageRect = fillImage.GetComponent<RectTransform>();
rectHeight = fillImageRect.rect.height/2;
incrementFactor = (fillImage.fillAmount * (fillImageRect.rect.height))- fillImageRect.rect.height/2;
this.GetComponent<RectTransform>().localPosition=new Vector3(0, incrementFactor, 0);
}
}
Thanks so much for your help, but I am getting the following error - "Assets\ManaBar\MoveableLine.cs(10,9): error CS0103: The name 'fillImageRect' does not exist in the current context" for each line it says fillImageRect. I am not much for coding, so I am not sure what is wrong. It is defined in your code.
I included another screen shot, in case the issue is my file na$$anonymous$$g.
Sorry and thanks!!

[1]: /storage/temp/180925-download.png
That's my fault when editing the post. Just change fillImageRect = to var fillImageRect = (add var there)
Thanks for that! It looks like you edited the original comment to include the var, so I copy and pasted the script as is above, but now I get a different error message (attached). Do you know I could try next?
Your answer
Follow this Question
Related Questions
Best way to make an animated infinite striped progress bar? 1 Answer
Changing text color based on background to make readable 1 Answer
Simple progress bar/timer 1 Answer
Problem with WWW.progress 3 Answers
Progress Bar Display help (Bonus) 2 Answers