Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Player Health Texture | HELP

Discussion in 'Scripting' started by GLucasDev2, Dec 25, 2013.

  1. GLucasDev2

    GLucasDev2

    Joined:
    Jul 24, 2013
    Posts:
    77
    Hello unity. So basically im trying to switch my FPS player from numerical display of health, thirst, and hunger over to a texture for each as obviously thats more aesthetically appeasing.

    Here is my code:

    Code (csharp):
    1. var healthTex:Texture2D;
    2. var backgroundTex:Texture2D;
    3. private var fpsPlayer:Component;
    4.  
    5. function Start() {
    6. fpsPlayer = GetComponent("FPSPlayer");
    7. }
    8. function OnGUI() {
    9. GUI.Texture(Rect(100,100, fpsPlayer.maximumHitPoints, 25),backgroundTex);
    10.  
    11. GUI.Texture(Rect(100,100, fpsPlayer.hitPoints / fpsPlayer.maximumHitPoints * fpsPlayer.maximumHitPoints, 25),backgroundTex);
    12. }
    Now i get this error message when i attach it to my player:

    Code (csharp):
    1. MissingMethodException: UnityEngine.GUI.Texture
    2.  
    3. Boo.Lang.Runtime.DynamicDispatching.MethodDispatcherFactory.ProduceExtensionDispatcher ()
    4.  
    5. Boo.Lang.Runtime.DynamicDispatching.MethodDispatcherFactory.Create ()
    6.  
    7. Boo.Lang.Runtime.RuntimeServices.DoCreateMethodDispatcher (System.Object target, System.Type targetType, System.String name, System.Object[] args)
    8.  
    9. Boo.Lang.Runtime.RuntimeServices.CreateMethodDispatcher (System.Object target, System.String name, System.Object[] args)
    10.  
    11. Boo.Lang.Runtime.RuntimeServices+<Invoke>c__AnonStorey14.<>m__7 ()
    12.  
    13. Boo.Lang.Runtime.DynamicDispatching.DispatcherCache.Get (Boo.Lang.Runtime.DynamicDispatching.DispatcherKey key, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory)
    14.  
    15. Boo.Lang.Runtime.RuntimeServices.GetDispatcher (System.Object target, System.String cacheKeyName, System.Type[] cacheKeyTypes, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory)
    16.  
    17. Boo.Lang.Runtime.RuntimeServices.GetDispatcher (System.Object target, System.Object[] args, System.String cacheKeyName, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory)
    18.  
    19. Boo.Lang.Runtime.RuntimeServices.Invoke (System.Object target, System.String name, System.Object[] args)
    20.  
    21. UnityScript.Lang.UnityRuntimeServices.Invoke (System.Object target, System.String name, System.Object[] args, System.Type scriptBaseType)
    22.  
    23. GUI Health.OnGUI () (at Assets/GUI Health.js:9)
    '

    Any help is appreciated!
     
  2. Erdroy

    Erdroy

    Joined:
    Jan 12, 2013
    Posts:
    19
    Try to use a GUI.DrawTexture(...);

    ~Erdroy
     
  3. Erdroy

    Erdroy

    Joined:
    Jan 12, 2013
    Posts:
    19
    Or GUI.Label, or GUI.Box
     
  4. GLucasDev2

    GLucasDev2

    Joined:
    Jul 24, 2013
    Posts:
    77
    Thank you! Also, is there a way to make these vertical? or do they have to be horizontal?

    So using this method, is there a way to make it draw the portions of the texture or will it just stretch and shrink the texture? Im basically trying to have it fill a vial such as in Diablo 3 and 2, but the texture isnt a plain red you know, so it looks wierd when it starts to shrink when losing health.
     
  5. MDragon

    MDragon

    Joined:
    Dec 26, 2013
    Posts:
    329
    Can you post a screenshot of what you mean exactly about filling the vial? Not so sure what you meant there.
     
  6. GLucasDev2

    GLucasDev2

    Joined:
    Jul 24, 2013
    Posts:
    77
    $sample.jpg $sample.jpg

    As you can see, the health texture is on the bottom left and is represented by a standing man, and when you lose health, the inside red decreases but the textures form still is there, it doesnt shrink to compensate for the healths loss it just basically in laymans term removes that part of the texture for the time being.
     
    Last edited: Dec 26, 2013