I’ve recently started unity, so as a sort of exercise I wanted to make a remake of a Mario level. The part where i got stuck is when I made patrolling Goombas. It may be an inefficient and basic method, but essentially the idea is that I made them reverse direction when hitting another object. The problem is, that for some reason, when one hits a wall, both of them reverse direction. The script is, of course, applied to both.
using UnityEngine;
using System.Collections;
public class GoombaMove : MonoBehaviour {
public static float speed = -0.01f;
// Update is called once per frame
void Update () {
this.transform.Translate(speed, 0, 0);
}
void OnTriggerEnter2D(Collider2D other)
{
speed *= -1;
}
}
I’m at a bit of a loss here…