C#C
C#3y ago
Raptorini

❔ How can I make an instantiated object move?

I'm trying to make an object spawned with the instantiate function move, but I can't get it to work. Can anyone help me?

public class Spawn_Cells : MonoBehaviour
{
public GameObject cell;
public float speed = 2;
public Vector3 cellDirection = new Vector3(1, 1, 0);

void Start()
{
Vector3 randomPosition = new Vector3(Random.Range(10f, -10f), Random.Range(4f, -4f), 0);
Instantiate(cell, randomPosition, Quaternion.identity);
}

void Update()
{
cell.transform.Translate(cellDirection * speed * Time.deltaTime);
}

}
Was this page helpful?