動く床の作り方


床を往復移動させる
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MoveFloor : MonoBehaviour
{
private Vector3 pos;
public float speed;
private int num = 1;
void Update()
{
// 現在位置の取得
pos = transform.position;
// (テクニック)
// numの数字が「1」のときは「右方向」に移動
// numの数字が「-1」のときは「左方向」に移動
transform.Translate(new Vector3(1, 0, 0) * Time.deltaTime * speed * num);
if(pos.x > 15)
{
num = -1;
}
if(pos.x < 6.5f)
{
num = 1;
}
}
}



【2022版】BallGame(全27回)
他のコースを見る

床を往復移動させる
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MoveFloor : MonoBehaviour
{
private Vector3 pos;
public float speed;
private int num = 1;
void Update()
{
// 現在位置の取得
pos = transform.position;
// (テクニック)
// numの数字が「1」のときは「右方向」に移動
// numの数字が「-1」のときは「左方向」に移動
transform.Translate(new Vector3(1, 0, 0) * Time.deltaTime * speed * num);
if(pos.x > 15)
{
num = -1;
}
if(pos.x < 6.5f)
{
num = 1;
}
}
}



動く床の作り方