0

我正在尝试创建一种 UI/HUD 栏来计算角色背面的弹药,例如 astroneer 或死区中的健康栏。我试图跟随这个reddid thred

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

但我无法让它工作,而且我没有使用着色器的经验。有人可以帮助我吗?


编辑:我发现了问题,基本上着色器与 HDR Pipeline 不兼容。是否有一种方法可以转换它或使用着色器图重新创建它?


这是着色器源代码,但您也可以在 thred 上找到它。你可以下载一个统一包。

    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"
}
4

1 回答 1

0

所以你基本上想要一个类似于健康栏的弹药栏,我不熟悉你尝试尝试的方法,但它似乎比它必须要复杂得多。一个更简单的方法是创建一个世界空间 UI 画布,您可以将其作为孩子附加到您的播放器上,并在该画布上创建一个健康栏。然后去改变健康栏的外观以适应你想要的。该视频是学习如何将 UI 元素放入世界空间的良好开端。

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

于 2020-08-02T16:32:27.300 回答