With this code my obstacle just start moving in one direction and pass through the wall, it doesn’t change direction. What to do?
int i = 1;
void Update()
{
transform.Translate(0, 2 * i * Time.deltaTime, 0);
}
private void OnCollisionEnter(UnityEngine.Collision collision)
{
if(collision.collider.tag == "Wall")
i *= -1;
}
I move it on Y axis because obstacle is rotated.