I can’t wrap my head around this problem. I’ve tried adding onCollisionEnter and onTriggerEnter on both my cube and my bullet prefab but neither of them detects a collision between them. I’ve searched on google on this problem but couldn’t find a solution that worked.
This is my script on my cube gameobject.
using UnityEngine;
using System.Collections;
public class testcollision : MonoBehaviour {
public GameObject bullet;
void onTriggerEnter(Collider other) {
if(other.gameObject.tag == "bullet" ) {
Destroy(this.gameObject);
}
}
void update() {
}
}
This is the inspector menu on the cube gameobject: http://i.imgur.com/M0WDZIX.png
This is how my bullet is being made. It gets shot from my player character.
using UnityEngine;
using System.Collections;
public class AutoattackBULLET : MonoBehaviour {
public GameObject Bullet_Emitter;
public GameObject Bullet;
public float Bullet_Foward_Force;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if(Input.GetKeyDown("a")) {
GameObject Temp_bullet_handler;
Temp_bullet_handler = Instantiate (Bullet, Bullet_Emitter.transform.position, Bullet_Emitter.transform.rotation) as GameObject;
Temp_bullet_handler.transform.Rotate(Vector3.left * 90);
Rigidbody Temp_Rigidbody;
Temp_Rigidbody = Temp_bullet_handler.GetComponent<Rigidbody>();
Temp_Rigidbody.AddForce(transform.right * Bullet_Foward_Force); //use transform.right
Destroy(Temp_bullet_handler, 0.4f);
}
}
}
This is the bullet prefab’s inspector menu: http://i.imgur.com/sFiAlZU.png
The bullet does bounce off the cube but I can’t get a collision check anywhere.
It is important to have OnTriggerEnter, but not onTriggerEnter (capital O is needed).