以下の方法で解決しました。
PosToShader.cs
1//これを目的のオブジェクトにアタッチ
2using System.Collections;
3using System.Collections.Generic;
4using UnityEngine;
5
6public class PosToShader : MonoBehaviour {
7
8 private MaterialPropertyBlock p;
9
10 private Material mat=null;
11
12 private Renderer rend=null;
13
14 // Use this for initialization
15 void Start () {
16 rend = this.GetComponent<Renderer> ();
17 this.mat = rend.material;
18 p = new MaterialPropertyBlock ();
19 }
20
21 // Update is called once per frame
22 void Update () {
23 p.Clear ();
24 p.SetVector ("_ObjectPosition", transform.position);
25
26 rend.SetPropertyBlock(p);
27
28 }
29}
30
Shader.shader
1Shader "Custom/Shader" {
2
3 SubShader {
4 Tags { "RenderType"="Opaque" }
5 LOD 200
6
7 CGPROGRAM
8 #pragma surface surf Standard
9 #pragma target 3.0
10
11 struct Input {
12 float3 worldPos;
13 };
14
15 float4 _ObjectPosition;//ここと
16
17 void surf (Input IN, inout SurfaceOutputStandard o) {
18 float dist = distance( _ObjectPosition, IN.worldPos);//ここを書き換え
19 float val = abs(sin(dist*3.0-_Time*100));
20 if( val > 0.98 ){
21 o.Albedo = fixed4(1, 1, 1, 1);
22 } else {
23 o.Albedo = fixed4(10/255.0, 10/255.0, 10/255.0, 0.3);
24 }
25 }
26 ENDCG
27 }
28 FallBack "Diffuse"
29}
30
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。