Unity2021から標準パッケージとなった”Visual Scripting(ビジュアルスクリプティング)”(旧Bolt)を使用して、プレイヤー(”Player”タグが付いたゲームオブジェクト)が当たると大きさが変わるゲームオブジェクトの作り方を紹介します。
プレイヤーとしては以下を使います。
完成動作
プレイヤー(unitychan)がCylinder(赤)に当たったらCylinderの大きさが変わります。
作り方
1.シーンに各オブジェクトを配置
1-1.以下のように配置する。床をPlane、プレイヤーをunitychan、当たったら大きさが変わるゲームオブジェクトをCylinder(赤)とした。

2.プレイヤー(”Player”タグが付いたゲームオブジェクト)に当たったら大きさが変わるビジュアルスクリプトを作成
2-1.Cylinderに”Script Machine”コンポーネントを追加


2-2.”Graph”プロパティの”New”ボタンを押下

2-3.ファイルの保存ダイアログが開かれるので任意の場所にChangeScaleという名前で保存する。

2-4.”Edit Graph”ボタンを押下して、以下のようにグラフを作成する。
※今回はx,z,y軸のscaleがそれぞれ3になる。

※ちなみに、現在のScaleの何倍かにしたい場合は以下のようにする。
x軸方向に2倍、y軸方向に3倍、z軸方向に4倍となる。

3.Colliderの”Is Trigger”にチェックは入れない
3-1.大きさを変えたいゲームオブジェクト(Cylinder)のCapsule Colliderの”Is Trigger”にチェックを入れない。
※ここにチェックが入っているとOnCollisionEnterイベントではなく、OnTriggerEnterイベントが発火してしまう。デフォルトではチェックは入っていないので大丈夫。

4.プレイヤーオブジェクトのTagに”Player”を設定
4-1.プレイヤーオブジェクト(今回はunitychan)のTagに”Player”を設定

完成
プレイヤー(unitychan)がCylinder(赤)に当たったらCylinderの大きさが変わる。
コメント