回答編集履歴

1

コメントに対する回答

2019/08/09 11:40

投稿

katsuko
katsuko

スコア3582

test CHANGED
@@ -103,3 +103,69 @@
103
103
 
104
104
 
105
105
  ```
106
+
107
+
108
+
109
+ > ちなみにUSE_PLANEをUpdateで使っている深い意味とかはあるんですか?
110
+
111
+
112
+
113
+ ```c#
114
+
115
+ void Update()
116
+
117
+ {
118
+
119
+ // 自身のトランスフォームのXZ平面の定義
120
+
121
+ Plane plane = new Plane(this.transform.up, this.transform.position);
122
+
123
+ // XZ平面上の点を求める。
124
+
125
+ this.result.position = this.target.position - plane.normal * plane.GetDistanceToPoint(this.target.position);
126
+
127
+ }
128
+
129
+ ```
130
+
131
+
132
+
133
+ 現状のままであれば、`Update`は上記のように動作しますが、
134
+
135
+
136
+
137
+ ```c#
138
+
139
+ //#define USE_PLANE
140
+
141
+ ```
142
+
143
+
144
+
145
+ というように、`USE_PLANE`の定義をコメントアウトすると、
146
+
147
+
148
+
149
+ ```c#
150
+
151
+ void Update()
152
+
153
+ {
154
+
155
+ // まぁ、この程度の計算であれば、内積で簡単に求められるんですけどね。
156
+
157
+ this.result.position = this.target.position - this.transform.up * Vector3.Dot(this.transform.position - this.target.position, -this.transform.up);
158
+
159
+ }
160
+
161
+ ```
162
+
163
+
164
+
165
+ 上記のようになります。
166
+
167
+
168
+
169
+ 要は、`USE_PLANE`の定義の有無で、動作の切り替えを行い、簡単に両方の動作の検証をするためのもので、大した意味はありません。
170
+
171
+ ただ、[ifディレクティブ](https://docs.microsoft.com/ja-jp/dotnet/csharp/language-reference/preprocessor-directives/preprocessor-if)、[#defineディレクティブ](https://docs.microsoft.com/ja-jp/dotnet/csharp/language-reference/preprocessor-directives/preprocessor-define)の使い方は、知っておいたほうが良いかもしれません。