自動でオブジェクトを移動させる
void Update () {
transform.position += new Vector3(0.1f , 0.0f , 0.0f);
}
プライヤーを追いかけるようにさせる
public ; Transform player
public float speed = 3; //移動速度 // Use this for initialization void Start () { player = GameObject.FindGameObjectWithTag("Player").transform; } // Update is called once per frame void Update () { Vector3 playerPos = player.position; //プレイヤーの位置 Vector3 direction = playerPos - transform.position; //方向 direction = direction.normalized; //単位化(距離要素を取り除く) transform.position = transform.position + (direction * speed * Time.deltaTime); transform.LookAt(player); //プレイヤーの方を向く }