LoginSignup
1
1

More than 1 year has passed since last update.

オブジェクトを上下にゆらゆらさせる

Posted at

ゆっくりその場から上下に動きます
インスペクタのspeedで上下運動のスピードを変えられます

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

public class UpDownLoop : MonoBehaviour
{

    Vector3 startPos;
    public float speed = 1.0f;

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

    void Update()
    {
        float sin = Mathf.Sin(Time.time * speed) +startPos.y; //ゲーム開始からの経過時間を1~-1に変換
        transform.position = new Vector3(startPos.x,sin,startPos.z); 
    }
}
1
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
1
1