- Home /
Question by
amiaz · Mar 28, 2017 at 07:08 AM ·
prefabprogress-bar
My progress bar is a prefab and I want it to be in the position of object with tag
this is my code:
public GameObject target; // the position i want the progress bar to be in
public float totalload = 100f;
public float currentload;
public Image img;
public Image background1;
public Image background2;
public Collision other;
void Start ()
{
currentload = totalload;
target = GameObject.FindGameObjectWithTag("P");
}
void Update ()
{
if(currentload >= 0)
{
currentload -= 0.5f;
img.transform.localScale = new Vector3((currentload / totalload), img.transform.localScale.y);
}
}
}
Comment
after line 20, stick this
img.transform.position = target.transform.position; // this will make the img object have the world location of the target every frame
Your answer
Follow this Question
Related Questions
Changes via script in prefab mode not applied to instances 0 Answers
Accessing children of instances vs children of original prefab 1 Answer
Instantiate prefab from original position to click mouse point position 0 Answers
Change a mesh in a prefab without resetting all the script and parameters? 1 Answer