動く床の作り方
![C24acb4c 318c 43e9 b1f5 f8cf6a797151](https://codegenius.org/uploads/slide/image/6868/c24acb4c-318c-43e9-b1f5-f8cf6a797151.jpeg)
![7f3805ac 37aa 414d 92d7 fc44001ff382](https://codegenius.org/uploads/slide/image/6869/7f3805ac-37aa-414d-92d7-fc44001ff382.jpeg)
動く床
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MoveFloor : MonoBehaviour
{
public float speed;
private Vector3 pos;
private bool isStop = false;
void Start()
{
pos = transform.position;
}
void Update()
{
if(isStop == false)
{
pos.x += Time.deltaTime * speed;
transform.position = pos;
if(pos.x > 15) // 終点(自由に変更可能)
{
isStop = true;
}
}
else if(isStop == true)
{
pos.x -= Time.deltaTime * speed;
transform.position = pos;
if(pos.x < 6) // 始点(自由に変更可能)
{
isStop = false;
}
}
}
}
![D037854e ac87 4f56 916b 9c8f1a5482c9](https://codegenius.org/uploads/slide/image/6870/d037854e-ac87-4f56-916b-9c8f1a5482c9.jpeg)
![67848683 81e7 4d41 992e 1f6651ec9241](https://codegenius.org/uploads/slide/image/6871/67848683-81e7-4d41-992e-1f6651ec9241.jpeg)
![B004addd 54ce 4384 8001 5fb9ee2015cc](https://codegenius.org/uploads/slide/image/6872/b004addd-54ce-4384-8001-5fb9ee2015cc.jpeg)
【2021版】BallGame(全31回)
他のコースを見る![C24acb4c 318c 43e9 b1f5 f8cf6a797151](https://codegenius.org/uploads/slide/image/6868/c24acb4c-318c-43e9-b1f5-f8cf6a797151.jpeg)
![7f3805ac 37aa 414d 92d7 fc44001ff382](https://codegenius.org/uploads/slide/image/6869/7f3805ac-37aa-414d-92d7-fc44001ff382.jpeg)
動く床
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MoveFloor : MonoBehaviour
{
public float speed;
private Vector3 pos;
private bool isStop = false;
void Start()
{
pos = transform.position;
}
void Update()
{
if(isStop == false)
{
pos.x += Time.deltaTime * speed;
transform.position = pos;
if(pos.x > 15) // 終点(自由に変更可能)
{
isStop = true;
}
}
else if(isStop == true)
{
pos.x -= Time.deltaTime * speed;
transform.position = pos;
if(pos.x < 6) // 始点(自由に変更可能)
{
isStop = false;
}
}
}
}
![D037854e ac87 4f56 916b 9c8f1a5482c9](https://codegenius.org/uploads/slide/image/6870/d037854e-ac87-4f56-916b-9c8f1a5482c9.jpeg)
![67848683 81e7 4d41 992e 1f6651ec9241](https://codegenius.org/uploads/slide/image/6871/67848683-81e7-4d41-992e-1f6651ec9241.jpeg)
![B004addd 54ce 4384 8001 5fb9ee2015cc](https://codegenius.org/uploads/slide/image/6872/b004addd-54ce-4384-8001-5fb9ee2015cc.jpeg)
動く床の作り方