I’m for the first time trying out 2D collision in unity and as usual I’m running into problems when I do so xD
This is what I got:
using UnityEngine;
using System.Collections;
public class EnemySpaceShip1 : MonoBehaviour {
public float health;
GameObject Score;
// Use this for initialization
void Start () {
Score = GameObject.FindWithTag("MainCamera");
}
// Update is called once per frame
void Update () {
transform.Rotate(Vector3.back * Time.deltaTime * 50);
if(health <= 0){
Score.GetComponent<Menu>().score += 10;
Destroy(gameObject);
}
}
void OnCollisionEnter2D(Collision2D col){
print("hit");
if(col.gameObject.tag=="Bullet"){
health -= 1;
}
}
}
The CollisionEnter2D does not even print out “hit” even though both my bullets and player itself clearly collides with each other.
Is there something I’ve done wrong or is there more to it than just this?