- Home /
The boss bullet won't collide with anything
Hi every one.
I'm a game development student and lately I made a tech demo for college. It is a 2D action platformer heavily inspired by Mega Man.
I came across this problem where the boss bullet won't collide with anything. It should collide with the walls but it isn't. :(
I'll be very grateful if someone can spot my mistake on the code.
using UnityEngine;
using System.Collections;
public class BossBullet : MonoBehaviour {
Transform myTransform;
Vector3 direction;
public float speed = 100f;
public int myDamage = 1;
void Awake()
{
myTransform = transform;
}
public void Setup(Vector3 newDirection, float newSpeed)
{
direction = newDirection;
speed = newSpeed;
}
void FixedUpdate ()
{
myTransform.position += direction * Time.fixedDeltaTime;
}
void OnTriggerEnter(Collider other)
{
if (other.tag == "Character")
{
//Make Character take damage
}
if(other.tag == "Wall")
{
Debug.Log("Hit Wall!");
Destroy(gameObject);
}
}
}
Comment
do you mean to be using OnTriggerEnter and not OnCollisionEnter
Best Answer
Answer by bemed · May 07, 2014 at 04:54 PM
I changed it to OnTriggerEnter2D (Collider2D other) and worked. Looks like I have to use the 2D variants of the classes.
Answer by FirePlantGames · May 06, 2014 at 11:33 PM
are you sure that you want to use OnTriggerEnter? maybe use OnCollisionEnter(Collision other)