我们制造一个子弹的模型

1 首先设置3d max中参数,设置Customize->Units Setup Metic为厘米

2 建模,这里我们使用plane,一个平面,如图

3 然后导出

4 unity中模型设置,如图

在这里有个参数Scale Factor,这个参数很重要,设置小了,导致在unity里面可能看不到,大了又不合适。

5 创建一个material

6 创建一个shader,把这个shader赋值给刚才创建的material

这里的shader代码如下

Shader "AngryBots2/FX2/Additive" {
    Properties {
        _MainTex ("Base", 2D) = "white" {}
        _TintColor ("TintColor", Color) = (1.0, 1.0, 1.0, 1.0)
    }
    
    CGINCLUDE

        #include "UnityCG.cginc"

        sampler2D _MainTex;
        fixed4 _TintColor;
        
        half4 _MainTex_ST;
                        
        struct v2f {
            half4 pos : SV_POSITION;
            half2 uv : TEXCOORD0;
        };

        v2f vert(appdata_full v) {
            v2f o;
            
            o.pos = mul (UNITY_MATRIX_MVP, v.vertex);    
            o.uv.xy = TRANSFORM_TEX(v.texcoord, _MainTex);
                    
            return o; 
        }
        
        fixed4 frag( v2f i ) : COLOR {    
            return tex2D (_MainTex, i.uv.xy) * _TintColor;
        }
    
    ENDCG
    
    SubShader {
        Tags { "RenderType" = "Transparent" "Reflection" = "RenderReflectionTransparentAdd" "Queue" = "Transparent"}
        Cull Off
        Lighting Off
        ZWrite Off
        Fog { Mode Off }
        Blend One One
        
    Pass {
    
        CGPROGRAM
        
        #pragma vertex vert
        #pragma fragment frag
        #pragma fragmentoption ARB_precision_hint_fastest 
        
        ENDCG
         
        }
                
    } 
    FallBack Off
}

7,创建texture,从这个shader中可以看出,使用的是一张2d纹理图片,把这个2d纹理图片拖到正确的位置上

8 material效果如下

9 最终射出的子弹效果图如下

以上就是设置的全过程。

 

这里需要我们对shader有个简单的了解。

posted on 2016-06-11 20:40  水榭阁主  阅读(6395)  评论(0编辑  收藏  举报