i have a scene 2D with a wall, a player, ground and a zombie. They all have collisions. I want the zombie to climb over the wall. The bit where it detects if it is a wall, for some reason, always gets triggered. Here is the code: using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class zombieAI : MonoBehaviour {
public Rigidbody2D rb;
public GameObject arm;
public Transform target;
public string state;
public int speed;
// Use this for initialization
void Start () {
state = "walk";
}
// Update is called once per frame
void Update () {
if (state == "walk")
{
rb.AddForce(new Vector2(0, speed));
}
}
private void OnCollisionEnter2D(Collision2D collision)
{
if (collision.gameObject.name == "wall")
{
rb.AddForce(new Vector2(300, 0));
}
}
}