◆前回

 

 

 

今回のお題は

Custom Triggers

 

Platformer Microgame - Unity Learn

トリガーはユニティとゲーム開発の強力なパーツ。

confettiを有効にするカスタムトリガーをつなぐ?方法を学ぼう

confettiは紙吹雪らしい。

 

何か条件を満たすと紙吹雪を降らせるみたいな感じでしょうか。

 

 

ではやっていきます!

 

1. In the Menu Bar, select GameObject > 2D Object > Sprite. This will be our “trigger”.

手順を見るとSpriteまでしかメニューがないのですが私の環境ではさらにサブメニューがありました。形の指定みたいなのでとりあえずSquareを選んでみます。

 

 

2. In the Inspector under Sprite Renderer, click on the circle next to None (Sprite). Search “TileGround” and double-click on it.

追加したスプライトのRenderer配下にあるSpriteの項目を変更します。

うしろのまる印をクリックするとウインドウが出てくるので指示通りTileGroundを選びます。

 

 

 

3. Using the Move and Scale tools, adjust the tile so that it covers up a portion of the scene that the Player can walk over.

プレイヤーが歩ける位置にSpriteを移動します。

 

 

4. Rename the GameObject to “ConfettiTrigger”.

Spriteの名前をConfettiTriggerに変更します。

左のオブジェクトのリストで名前をクリックして変えるか、右側のInspectorウインドウの一番上のオブジェクト名を変更するか、どっちでも変えられます。

 

 

5. In the Inspector, click on Add Component and search for Box Collider 2D. Click on it to add it.

InspectorウインドウのAdd Componentを押して、Physics 2D > Box Collider 2Dの順に選択します。手順は検索することになっているけど名前からだいたい予想できますね。

 

 

6. In the Inspector, under the Box Collider component, check the Is Trigger box.

Is Triggerをチェック!

 

 

7. In the Inspector, click on Add Component and search for Simple Trigger. Click on it to add it to the ConfettiTrigger.

今度はAdd componentでScript > Simple Triggerを選択します。

なんとなく構成が理解出来てきた気がします。

 

 

8. Drag in Player from the Hierarchy to the TriggerBody field inside of the Simple Trigger script.

オブジェクトリストのPlayerをドラッグせよ、とか書いてますけど、↑みたいにTrigger Bodyのうしろのまる印を押すと選択ウインドウが出てくるので、そこでPlayerを選んでも良さそうです。

 

 

たぶんこれでプレイヤーと追加したSpriteとの衝突判定がされるのでしょう。

次からはぶつかったときに何をするのかを設定するのかな。

 

 

 

9. In the Project View, find ConfettiCelebration under Assets > UTech > MG-Platformer > ModAssets > Platformer > Particle Prefabs > ConfettiCelebration.

ProjectウインドウでConfettiCelebrationを検索します。

たどってもいいけど、Assetsの構成が違ったりするから検索のほうが早そう。

 

10. Drag the ConfettiCelebration prefab into the Hierarchy on top of ConfettiTrigger. This will make it a child of ConfettiTrigger, and make it centered on top of it.

検索して出てきたプレハブをConfettiTrigger配下になるようにドラッグします。

 

 

11. Click on ConfettiTrigger, and in the Simple Trigger component click + underneath On Trigger Enter ().

Simple TriggerのOn Trigger Enter()のところの+をクリック。

 

 

12. From the Hierarchy (not the Project View!), drag in ConfettiCelebration onto the None (Object) field. Alternatively, you can click on the circle next to None (Object) to search for it.

On Trigger Enter()のNone(Object)になってるところに、ConfettiCelebrationを設定します。

うしろの丸印を押して、ウインドウが出てきたらタブでSceneを選んでからConfettiCelebrationを探して選択します。

 

13. Click on the dropdown that says No Function and select ParticleSystem > Play.

No Functionのところを変更します。

 

14. Now we just need to hide the ConfettiTrigger mesh so that you don’t see it on the road. Uncheck the box next to Sprite Renderer.

Sprite Rendererのチェックを外して表示されないようにします。

 

15. Click Play and watch the confetti fly out when you cross the box!

実際動かしてみました。

Triggerオブジェクトにぶつかったタイミングで紙吹雪?のエフェクトが出ました!

 

 

◆次回

 まだないよ。