2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

床が自動で動くと同時にPlayerも一緒に動く方法

Posted at

前回の続きです。

void OnCollisionStay(Collision collision)
    {
        if (collision.gameObject.tag == "Stage")
        {
            transform.parent = collision.gameObject.transform;
        }
    }
    void OnCollisionExit()
    {
        transform.parent = null;
    }

動く床にCollisionをつけてタグも設定し、Playerスクリプトに書きます。
OnCollisionStayはブジェクト同士が接触している間なので、
Stageタグの上に乗っている間Playerが移動する。
OnCollisionExitはオブジェクト同士が接触から離れた瞬間なので
離れた瞬間はnullします。
こうすることで床が動くと同時にPlayerも動くようになります。

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?