- Home /
Question by
Panny123 · Nov 23, 2014 at 06:28 PM ·
movinggameobject
Moving object to another object
So, I have two prefabs which I have made to a gameobject. Now I want the gameobject to move towards the other gameobject. I don't know what to do next maybe you guys could help me out, I'd really appreciate it!
using UnityEngine; using System.Collections;
public class EnemyBehaviour : MonoBehaviour {
GameObject player = Instantiate(Resources.Load("Player")) as GameObject;
GameObject enemy = Instantiate(Resources.Load("BasicEnemy")) as GameObject;
public Transform target = player;
public float speed;
void Update() {
float step = speed * Time.deltaTime;
transform.position = Vector3.MoveTowards(transform.position, target.position, step);
}
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613172247im_/https://answers.unity.com/themes/thub/images/avi.jpg)