void OnCollisionEnter(Collision col) { if (col.gameObject.layer == 11) { bullet bulletScript = col.gameObject.GetComponent <bullet>(); if (bulletScript != null) { bulletScript.OnCollided(col); HUDInfo.UpdateDestruction(1); } } }
void OnCollisionEnter(Collision col) { Debug.Log("Colliding!"); if (col.rigidbody.gameObject.name == gameObject.name) { //colliding with ourselves, ignore Debug.Log("Colliding with ourselves"); } else { //Colliding on impactable if (col.gameObject.layer == 11) { //Debug.Log(gameObject.name + " collided with " + col.gameObject.name); bullet bulletScript = col.gameObject.GetComponent <bullet>(); int weaponType = -2; if (bulletScript != null) { weaponType = bulletScript.getType(); } switch (weaponType) { case -1: break; case 0: //Right Trigger rightBulletHitCount++; if (bulletScript != null) { bulletScript.OnCollided(col); } if (rightBulletHitCount >= rightHitDestructionAmount) { Debug.Log("Destroying the building: " + name); destructMesh.SetActive(true); GameObject.Destroy(gameObject); HUDInfo.UpdateDestruction(destructionAmount); } else { HUDInfo.UpdateDestruction(destructionBit); } break; case 1: //A weapon break; case 2: break; case 3: break; case 4: break; default: Debug.Log("building collision: unsupported weaponType. Type: " + weaponType); break; } bulletScript.OnCollided(col); } } }