- Home /
Question by
Christian.Tucker · Nov 07, 2013 at 11:51 PM ·
unity 4textureing
Repeating a texture?
Trying to venture into UnityGUI here and I'm trying to attempt a Healthbar similar to the Old Mega-Man X.
http://remyvanruiten.files.wordpress.com/2013/01/full-health.png
^^For those who don't know what it is^^
No-matter what I try, the sprite is always drawn in the middle of the box.
using UnityEngine;
using System.Collections;
public class GUIManager : MonoBehaviour
{
public Texture aTexture;
private float maxHealth;
private float currHealth;
private float TopHUDHeight = 608;
private float HUDHeight = 162;
void Start()
{
maxHealth = 100f;
currHealth = maxHealth;
aTexture.wrapMode = TextureWrapMode.Repeat;
}
void Update()
{
currHealth = 100f;
}
void OnGUI()
{
GUI.Box(new Rect(0, TopHUDHeight, Screen.width, HUDHeight), "");
GUI.Box (new Rect(0, TopHUDHeight, 240, HUDHeight), "Inventory/Money");
GUI.Box (new Rect(241, TopHUDHeight,25, HUDHeight), "H\nE\nA\nL\nT\nH");
GUILayout.BeginVertical();
GUI.DrawTexture(new Rect(241, TopHUDHeight, 25, HUDHeight), aTexture, ScaleMode.ScaleToFit);
GUILayout.EndVertical();
GUI.Box (new Rect(267, TopHUDHeight, 490, HUDHeight), "Chat");
GUI.Box (new Rect(758,TopHUDHeight,25, HUDHeight), "E\nX\nP");
GUI.Box (new Rect(784, TopHUDHeight, 240, HUDHeight), "Gun/Ammo");
}
}
Comment
Answer by Huacanacha · Nov 08, 2013 at 12:01 AM
Texture has a 'wrapMode' variable. Make sure yours is set to TextureWrapMode.Repeat and it should tile.
I have Used the TextureWrap$$anonymous$$ode.Repeat as suggested, however it's not working.
According to the GUI.DrawTexture docs it takes a regular Texture.
Try the different Scale$$anonymous$$odes when calling DrawTexture.
Your answer
![](https://koobas.hobune.stream/wayback/20220613121430im_/https://answers.unity.com/themes/thub/images/avi.jpg)