0
0

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.

床が自動で動く方法

Posted at

空中アスレチックを作成していて、床が自動で動く方法をご紹介します。

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class UpDown : MonoBehaviour
{
    private Vector3 StagePos;  //StagePos変数を設定

void Start()
    {
        StagePos = transform.position;
    }

    void Update()
    {
        transform.position = new Vector3(StagePos.x, Mathf.Sin(Time.time) * 5.0f + StagePos.y, StagePos.z);
    }
}

Mathf.Sin関数を使います。
5.0fは動く範囲を判断。
今回は上下に動く床を作りたかったのでyに足しています。
左右に動いてほしかったらxに足せば良いです。

床が動くとPlayerも動かさないと落ちてしまいます。
つまり、床の上に乗るとPlayerは一緒に動いてくれません。
次回はPlayerも一緒に動かす方法をご紹介します。

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?