まず、ドアを作成します。
ヒエラルキー上で右クリック -> 2D Object > Sprites > Squareを選択します。
Layer を MovingPlatforms に変更。
以下のコンポーネントを追加します。
・Box Collider 2D
・Rigidbody 2D
・Moving Platform
Rigidbody 2D > Body Type を Kinematic に変更。
Moving Platformを以下のように変更。
必須:Cycle Option = Stop At Bounds
Path Elements -> サイズを2にして、Element 1でドアが開く位置に変更。
Scipt Activated に ☑
任意:Movement Speedの変更。Update Mode = Fixed Updateへ変更。
続いて、ドアを開くトリガーを作成します。
ヒエラルキー上で右クリック -> Create Emptyでオブジェクトを作成。
以下のコンポーネントを追加します。
・Box Collider 2D
・Key Operated Zone
今回は接触がわかりやすいようにSprite Renderer(にんじん)を追加しました。
Key Operated Zone を以下のように変更します。
・Requirements >
Requires Player Typeの☑を外す
Requires Button Activation Abilityの☑を外す
・Activation Conditions >
Auto Activationに☑をつける
・Actions >
On Activation () と On Exit () の “+”を押して、先ほど作ったドア(Square)をドロップ。
On Activation () は MovingPlatform -> MovingPlatform.MoveTowardsEnd()
On Exit () は MovingPlatform -> MovingPlatform.MoveTowardsStart()を選択。
・Key >
Requires Key の☑を外す
Key ID = 0
Key Action () の “+”を押す
コメント