- Home /
move another object when 2 other objects collide
hi, i'm trying to make it so that when the player collides with an object called trigger1, it makes another object called wall1 move down and i dont know how to do this, here is my code
public float moveSpeed = 10f;
void OnCollisionEnter (Collision col)
{
if (col.gameObject.name == "trigger1")
{
transform.Translate (Vector3.down * moveSpeed * Time.deltaTime);
}
}
i know this only makes the trigger1 objec move down but how can i make it move another object down instead
Comment
Best Answer
Answer by Sergio7888 · Nov 12, 2016 at 08:45 PM
Use a referecne to the other object transform and set it in the inspector or by code.
public Transform wall;
public float moveSpeed = 10f;
void OnCollisionEnter (Collision col)
{
if (col.gameObject.name == "trigger1")
{
wall.Translate (Vector3.down * moveSpeed * Time.deltaTime);
}
}