一定間隔で壁を上下させる方法


一定間隔でオブジェクトを上下させる方法
using UnityEngine;
using System.Collections;
public class MoveWall : MonoBehaviour {
// timeCountという箱を作って、中に0というデータを入れる(変数の定義+代入)
private float timeCount = 0;
// (テクニック)フラグを立てる
private bool isWall = false;
void Update () {
// timeCountの中身をフレームが更新されるたびごとに1ずつ増加させる。
timeCount += 1;
// timeCountが300ごと、「かつ」isWallの箱の中身がfalseと等しい時、
if(timeCount % 300 == 0 && isWall == false){
// 「MoveTo」は「指定したオブジェクト」を「指定した場所」に「指定した時間」で移動させるメソッド
iTween.MoveTo(this.gameObject, iTween.Hash("y", 1.5, "time", 5));
// isWallの箱の中身を「true」にする。
isWall = true;
} else if(timeCount % 300 == 0 && isWall == true){
iTween.MoveTo(this.gameObject, iTween.Hash("y", -1.5, "time", 5));
isWall = false;
}
}
}
Unity Code Memo
他のコースを見る

一定間隔でオブジェクトを上下させる方法
using UnityEngine;
using System.Collections;
public class MoveWall : MonoBehaviour {
// timeCountという箱を作って、中に0というデータを入れる(変数の定義+代入)
private float timeCount = 0;
// (テクニック)フラグを立てる
private bool isWall = false;
void Update () {
// timeCountの中身をフレームが更新されるたびごとに1ずつ増加させる。
timeCount += 1;
// timeCountが300ごと、「かつ」isWallの箱の中身がfalseと等しい時、
if(timeCount % 300 == 0 && isWall == false){
// 「MoveTo」は「指定したオブジェクト」を「指定した場所」に「指定した時間」で移動させるメソッド
iTween.MoveTo(this.gameObject, iTween.Hash("y", 1.5, "time", 5));
// isWallの箱の中身を「true」にする。
isWall = true;
} else if(timeCount % 300 == 0 && isWall == true){
iTween.MoveTo(this.gameObject, iTween.Hash("y", -1.5, "time", 5));
isWall = false;
}
}
}
一定間隔で壁を上下させる方法