Raptorini
✅ How to reference gameObject in OnCollisionEnter2D?
I don't want to detect collision of the game object the script is tied to, I want to detect collision of an instantiated object called _cell. How do I reference _cell in the collision function?
9 replies
❔ 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);
}
}
13 replies
❔ How to make instantiated object move using transform function?
public GameObject cell;
public float speed = 1;
public Vector3 cellDirection = new Vector3(1,1,0);
void Start()
{
Vector3 randomPosition = new Vector3(Random.Range(10, -10), Random.Range(4, -4), 0);
Instantiate(cell, randomPosition, Quaternion.identity);
}
void Update()
{
cell.transform.Translate(cellDirection * speed * Time.deltaTime);
}
For now, I wanna spawn a cell in a random place and make it move in a certain direction. The spawning works, but the cell will not move. Can anyone help me with this?
2 replies
❔ How to make instantiated object move with transform function?
I'm quite new to Unity, so this might be really easy.
public GameObject cell;
public float speed = 1;
public Vector3 cellDirection = new Vector3(1,1,0);
void Start()
{
Vector3 randomPosition = new Vector3(Random.Range(10, -10), Random.Range(4, -4), 0);
Instantiate(cell, randomPosition, Quaternion.identity);
}
void Update()
{
cell.transform.Translate(cellDirection * speed * Time.deltaTime);
}
For now, I wanna spawn a cell in a random place and make it move in a certain direction. The spawning works, but the cell will not move. Can anyone help me with this?
2 replies