1)一定時間ごとに、特定の場所にワープさせる。それがループする。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class WarpMove : MonoBehaviour
{
void Start()
{
StartCoroutine(Warp());
}
private IEnumerator Warp()
{
while(true)
{
// 1.5秒後ごとにワープ移動する。
yield return new WaitForSeconds(1.5f);
transform.position = new Vector3(-5, 1, 0);
yield return new WaitForSeconds(1.5f);
transform.position = new Vector3(5, 1, 0);
yield return new WaitForSeconds(1.5f);
transform.position = new Vector3(5, 5, 0);
yield return new WaitForSeconds(1.5f);
transform.position = new Vector3(-5, 5, 0);
}
}
}

2)一定時間ごとに、ランダムな場所にワープさせる。それがループする。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class WarpMove : MonoBehaviour
{
void Start()
{
StartCoroutine(Warp());
}
private IEnumerator Warp()
{
while (true)
{
// 1.5秒後ごとにワープ移動する。
yield return new WaitForSeconds(1.5f);
// ランダムな値を取得する。
float posX = Random.Range(-5, 5);
float posY = Random.Range(0, 8);
float posZ = Random.Range(-5, 5);
transform.position = new Vector3(posX, posY, posZ);
}
}
}
