動く敵の作り方2(Lライン)
敵を動かす(Lライン)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EnemyYMove : MonoBehaviour
{
[Range(0, 50)]
public float moveDistance;
private Vector3 pos;
private bool isReturn = false;
void Update()
{
pos = transform.position;
if (pos.z > 0 && isReturn == false)
{
// 下方向に移動
transform.Translate(0, 0, -moveDistance * Time.deltaTime, Space.World);
}
else
{
// 右方向に移動
isReturn = true;
transform.Translate(moveDistance * Time.deltaTime, 0, 0, Space.World);
}
}
}
敵を動かす(Lライン)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EnemyYMove : MonoBehaviour
{
[Range(0, 50)]
public float moveDistance;
private Vector3 pos;
private bool isReturn = false;
void Update()
{
pos = transform.position;
if (pos.z > 0 && isReturn == false)
{
// 下方向に移動
transform.Translate(0, 0, -moveDistance * Time.deltaTime, Space.World);
}
else
{
// 右方向に移動
isReturn = true;
transform.Translate(moveDistance * Time.deltaTime, 0, 0, Space.World);
}
}
}
動く敵の作り方2(Lライン)