Hi!
I´m new in this Unity World and maybe I am missing some basic concepts but I have been getting crazy with a problem for the past week. I don´t really find someone with the same problems so I hope someone can help me.
I have a game in 2D where I have a gameObject that is a Spider, ok? It has a RigibBody2D (dynamic) and a Box Collider 2D attached. I basically want my spider not to fall when reaching the end of the platform. I decided to implement this by creating a Left and Right Guide on the sides of it and attach them a Box Collider 2D (triggers both). I created a Script for them, as follows:
*
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EnemyMovingController : MonoBehaviour {
public EnemyControllerScript enemyObject = null;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
void onTriggerEnter2D(Collider2D otherObj){
Debug.Log ("Touched platform");
}
void onTriggerExit2D(Collider2D otherObj){
Debug.Log ("Leaving platform");
if (otherObj.tag == "Platform")
enemyObject.switchDirections ();
}
}
In my inspector I put the Spider object on the enemyObject.
I don´t know why this is not working. I mean, it is not entering on the onTriggerEnter2D and the exit. So my spider touches the platform and nothing happens and is falling when leaving it.
Both objects are children of the Spider. I also have other children (Another box collider 2d )to detect my players bullets and that collision works. I do not got the difference between them.
Any ideas?
Thanks in advanced.