Instantiate (clone) object doesn't move
The scene is that the player can automatically shoot enemies if close enough. The shooting will be lasted if the enemy in player's range. The issue is that every bullets just cloned but can't move.
Also, to some reason, i didn't add rigidbody for the bullet prefeb.
Here's my code in void Update():
if (Vector3.Distance (player.position, enemy.transform.position) < 10f) {
if (Time.time > nextFire) {
nextFire = Time.time + fireRate;
GameObject b = Instantiate (bullet, transform.position, transform.rotation) as GameObject;
b.transform.position = Vector3.MoveTowards (transform.position, enemy.transform.position, Time.deltaTime * moveSpeed);
}
}
It might be because you're telling the bullet to move within the same if statement it was created. Why don't you try creating a script for the bullet, then in it's update method code it to move under whatever conditions? Attach that script to the bullet prefab, so when it's instantiated it'll act on it's script.
Hope that helps, good luck!
Your answer

Follow this Question
Related Questions
Why my clone gameobject cannot move? 0 Answers
Why Original GameObject Destroy Clones ? 0 Answers
Preventing null when loading or cloning 1 Answer