Hi, I am new at unity3D. I try to make a basic wall by using “cube”, I add “box collider 2D” to the wall and to my player. I gave “Wall” tag to my wall. in both objects I put V on the trigger.
in some reason I can’t catch collisions, this is my player code:
private float speed = 2f;
private bool startMoveRight = false;
private bool startMoveLeft = false;
void Start (){
}
void Update () {
if ( Input.GetKey( "right" ) || startMoveRight ) {
transform.Translate( new Vector3( speed, 0, transform.position.z ) * Time.deltaTime );
startMoveRight = true;
} else if ( Input.GetKey("left") || startMoveLeft ) {
transform.Translate( new Vector3( -speed, 0, transform.position.z ) * Time.deltaTime );
startMoveLeft = true;
}
}
void OnTriggerEnter2D(Collider2D target){
Debug.Log("even not here");
if ( target.gameObject.tag == "Wall" ){
Debug.Log("here");
//stop moving
startMoveRight = false;
startMoveLeft = false;
}
}
my console is empty after I run the game!
I tried use OnTriggerEnter(Collider target) same issue.
thanks.