【Unity】Visual Scriptingでプレイヤーが当たったら色が変わるゲームオブジェクトを作る
Unity2021から標準パッケージとなった"Visual Scripting(ビジュアルスクリプティング)"(旧Bolt)を使用して、プレイヤー("Player"タグが付いたゲームオブジェクト)が当たると色が変わるゲームオブジェクトの作り方を紹介します。
プレイヤーとしては以下を使います。
完成動作
プレイヤー(unitychan)がCylinderに当たったら、Cylinderの色が変わります。
作り方
1.シーンに各オブジェクトを配置
1-1.以下のように配置する。床をPlane、プレイヤーをunitychan、当たったら色が変わるゲームオブジェクトをCylinderとした。
![](https://programming.sincoston.com/wp-content/uploads/2022/05/image-56.png)
2.プレイヤー("Player"タグが付いたゲームオブジェクト)に当たったら色が変わるビジュアルスクリプトを作成
2-1.Cylinderに"Script Machine"コンポーネントを追加
![](https://programming.sincoston.com/wp-content/uploads/2022/05/image-57.png)
![](https://programming.sincoston.com/wp-content/uploads/2022/05/image-58.png)
2-2."Graph"プロパティの"New"ボタンを押下
![](https://programming.sincoston.com/wp-content/uploads/2022/05/image-3.png)
2-3.ファイルの保存ダイアログが開かれるので任意の場所にChangeColorという名前で保存する。
![](https://programming.sincoston.com/wp-content/uploads/2022/05/image-59.png)
2-4."Edit Graph"ボタンを押下して、以下のようにグラフを作成する。
![](https://programming.sincoston.com/wp-content/uploads/2022/05/image-60-1024x322.png)
3.Colliderの"Is Trigger"にチェックを入れない
3-1.CylinderのCapsule Colliderの"Is Trigger"にチェックを入れない。
※ここにチェックが入っているとOnCollisionEnterイベントではなく、OnTriggerEnterイベントが発火してしまう。デフォルトではチェックは入っていないので大丈夫。
![](https://programming.sincoston.com/wp-content/uploads/2022/05/image-14.png)
4.プレイヤーオブジェクトのTagに"Player"を設定
4-1.プレイヤーオブジェクト(今回はunitychan)のTagに"Player"を設定
![](https://programming.sincoston.com/wp-content/uploads/2022/05/image-15.png)
完成
プレイヤー(unitychan)がCylinderに当たるとCylinderの色が赤色に変わります。
ディスカッション
コメント一覧
まだ、コメントがありません