Unity2021から標準パッケージとなった”Visual Scripting(ビジュアルスクリプティング)”(旧Bolt)を使用して、回転し続けるゲームオブジェクトを作る方法を紹介します。
完成動作
ゲームオブジェクトが回転し続けています。
作り方
1.シーンに各オブジェクトを配置
1-1.以下のように回転させたいゲームオブジェクト(今回はCube)を配置する。

2.ゲームオブジェクトを回転させるビジュアルスクリプトを作成
2-1.Cubeに”Script Machine”コンポーネントを追加


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

2-3.ファイルの保存ダイアログが開かれるので任意のフォルダにRotateという名前で保存する。
今回は、Assetsフォルダ配下にVisualScriptsフォルダを作成して、そこにRotateという名前で保存。

以下のようになる。(TitleとSummaryは任意)

2-4.以下のように変数を作成。
※それぞれのValueには1秒間で回転させたい角度を入れる。

2-5.以下の画像の”Edit Graph”ボタンを押下して、以下のようにグラフを作成する。
※”Get Delta Time”をそれぞれの変数に掛けることで、1秒間で指定した変数の値の角度だけ回転するようになる。掛けない場合は、パソコンの性能によって1秒間に実行される”On Update”イベントの回数は異なるので回転するスピードもパソコンごとに異なってしまう。


完成
これでゲームオブジェクトが1秒ごとに指定した角度回転し続ける。
コメント