Canvas/Panel and Heart Prefab

I have a question about adding “Heart” Health prefab to a panel inside of a canvas so that when I switch between Mobile and WebPlayer…it resizes perfectly. I currently have a hierarchy that looks like this…
-hearts (empty gameObject with a script on it)

I have two other items on the same Panel(in a different project, I’m just trying to get this to work) and they scale Perfectly but they are just UI Text items. The Hearts will be added at the start of the game and how many is decided before start up. Currently, it works but doesn’t scale well with the Panel. I would like to attach them to the panel and it scale with the panel and I’m not sure if I’m even headed in the right direction with it…here is a few bits of code that is what I’m working with


public class heartAdder : MonoBehaviour {
	public GameObject heartGUI;
	public Vector2 startPoint = new Vector2(0.05f,0.95f);
	public float distance = 0.04f;

	GameObject P;
	private float x;
	private float y;
	private float z;

	void addHearts (int amount){
		P = GameObject.Find ("hearts");
		RectTransform RT = (RectTransform)P.transform;

		x = RT.localPosition.x;
		y = RT.localPosition.y;
		z = RT.localPosition.z;

		for(int i = 0;i < amount;i++){
			Vector3 pos = new Vector3(startPoint.x+(distance*i), startPoint.y,0);
			//Vector3 pos = new Vector3(x+(distance*i), y,0);
			GameObject heartPrefab = Instantiate(heartGUI, pos, Quaternion.Euler(0,0,0)) as GameObject; = "heart"+(i+1).ToString();
			heartPrefab.transform.parent = transform;

script 2; that calls the heart adder

![void Start () {
		health = hearts*2;
		//GameObject getHearts = GameObject.Find("GUI/hearts");
		GameObject getHearts = GameObject.Find ("Panel/hearts");
		getHearts.SendMessage("addHearts", hearts, SendMessageOptions.DontRequireReceiver);
		GUITexture[] allChildren = getHearts.GetComponentsInChildren<GUITexture>();
		heartsGUI = new GUITexture[allChildren.Length];
		health = allChildren.Length*2;
		for(int i = 0;i < allChildren.Length;i++){
			heartsGUI _= allChildren *as GUITexture;*_

* }*
* rend = GetComponent();*
* }][1]*
hopefully there is enough information here to get what I’m asking,
Thanks in advance for any hints/tips/guidance!!!

Not sure if this is the best answer. But in my case everytime i set a gameObject as a child of another gameObject i always set its localscale as well.

Something like this:

 GameObject heartPrefab = Instantiate(heartGUI, pos, Quaternion.Identity) as GameObject; = "heart";
heartPrefab.transform.parent = transform;
heartPrefab.transform.localScale =;

My answer for this question was to not even use what i was using above really. I Completely Skip over the heart adder script because that is where i was getting the most issues it seemed. In the end…i ended up creating a hierarchy like this
-hearts(empty gameObject)
-heart1(UI Image)
-heart2(UI Image)
-heart3(UI IMage)

on each of the heart UI’s i set the source image to full health/heart

then inside of the 2nd script up above…i commented out the call to the heartadder script and changed everything from a GUITexture or Texture to a UI Image (DONT FORGET TO IMPORT( using UnityEngine.UI)). Set my images for the health during the game(full health/half health/empty health images) and then anytime took damage…called they UpdateHealth…and depending how your implementing it…set the correct heart/health image to full/half/empty.

AND THE BEST THING ABOUT IT IS, IT SCALES PERFECTLY FINE NOW!!! lol…Its kind of a brute force way of implementing it but if need a solution to work with…it works.

Thank you for you response up above! Much appreciated alteredgene-london!