0

I'm trying to create a sort of UI/HUD bar for counting ammunition in the back of the character, such as the health bar in astroneer or deadspace. I tried to follow this reddid thred

https://www.reddit.com/r/Unity3D/comments/6pixhk/how_to_build_the_hudui_on_the_player_like_in/

but I can't make it work and I have no experience with shaders. Can somebody help me?


Edit: I found the problem, basically the shader is not compatible with HDR Pipeline. Is there a Method to convert it or re-create it with the shader graph?


This is the shader source code, but you can also find it on the thred. There is a unitypackage you can download.

    Properties {
        _Color ("Color", Color) = (1,1,1,1)
        _MainTex ("Albedo (RGB)", 2D) = "white" {}
        _Glossiness ("Smoothness", Range(0,1)) = 0.5
        _Metallic ("Metallic", Range(0,1)) = 0.0
        _Threshold ("Threshold", Range(0,1)) = 0.0
        _EmissionColor ("Emission Color", Color) = (1,1,1,1)
        _EmissionPower ("Emission Power", Range(0,10)) = 1.0
    }
    SubShader {
        Tags { "RenderType"="Opaque" }
        LOD 200

        CGPROGRAM
        // Physically based Standard lighting model, and enable shadows on all light types
        #pragma surface surf Standard fullforwardshadows

        // Use shader model 3.0 target, to get nicer looking lighting
        #pragma target 3.0

        sampler2D _MainTex;

        struct Input {
            float2 uv_MainTex;
        };

        half _Glossiness;
        half _Metallic;
        float _Threshold;
        fixed4 _Color;
        fixed4 _EmissionColor;
        float _EmissionPower;

        // Add instancing support for this shader. You need to check 'Enable Instancing' on materials that use the shader.
        // See https://docs.unity3d.com/Manual/GPUInstancing.html for more information about instancing.
        // #pragma instancing_options assumeuniformscaling
        UNITY_INSTANCING_BUFFER_START(Props)
            // put more per-instance properties here
        UNITY_INSTANCING_BUFFER_END(Props)

        void surf (Input IN, inout SurfaceOutputStandard o) {
            fixed4 c = _Color; tex2D (_MainTex, IN.uv_MainTex) * _Color;
            o.Albedo = c.rgb;
            o.Metallic = _Metallic;
            o.Smoothness = _Glossiness;
            o.Alpha = c.a;

            if(IN.uv_MainTex.y < _Threshold) {
                o.Emission = _EmissionColor * _EmissionPower;
            }

        }
        ENDCG
    }
    FallBack "Diffuse"
}
simonpier
  • 1
  • 1

1 Answers1

0

so you basically want a ammunition bar similar to a health bar, i am not familiar with the method you are trying to attempt but it seems much more complicated than it has to be. a simpler way to go about this is you create a world space UI canvas that you can attach to your player as a child, and create a health bar on that canvas. then go about changing the look of the health bar to fit what you are trying to go for. this video is a good start when learning how to put UI elements in world space.

https://www.youtube.com/watch?v=ZYeXmze5gxg

  • Thanks a lot, but actually is not like what I had in mind. Like the thread, I was thinking about a 3d model with a color part that scale with the ammount of the munitions. here is an example: https://drive.google.com/file/d/1Ov7BLix8Tq7eycVsEtHPi_1BwzBzyqiV/view?usp=sharing – simonpier Aug 02 '20 at 17:38
  • i see, so if you want it to be a 3d model, maybe try putting the ammo bar UI into a empty 3d capsule like the image you sent, that should give the illusion of a 3d ammo bar. this is just an idea, sorry if you did not find what you were looking for. – Johnfrom_Indomi Aug 02 '20 at 19:12