LoginSignup
20
14

More than 5 years have passed since last update.

unityのオブジェクトを上下に移動させる。

Posted at

上下にピストン運動させるのにシンプルな関数としてPingPong関数が使える。
Mathf.PingPong(時間,上下値)

Timeクラスを使うとゲーム起動からの経過時間を取得する事ができます。

objAnimation.cs
using UnityEngine;
using System.Collections;
public class ObjAnimation : MonoBehaviour { 
    void Update () {
        transform.position = new Vector3(transform.position.x, Mathf.PingPong(Time.time,10), transform.position.z);
    }
}

これでオブジェクトは上下に移動します。
sample.jpg

20
14
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
20
14