Quantcast
Channel: Latest Questions by rjan
Viewing all articles
Browse latest Browse all 4

C# How to apply damage to enemys? Shooter

$
0
0
Hey, I am kindly new to Unity3d and c# and I don´t understand how I could let a bullet deal damage to an other object. I´ve seen a lot of JS tutorials but no for C#. I´ve tried to use them, but it wont work. My code I´ve tried: For the Bullet (Prefab) // Update is called once per frame void Update () { transform.Translate (0, 0, speed); } void OnTriggerEnter(){ if(gameObject.CompareTag("enemy")) { gameObject.SendMessage("OnDamage", damage); } } And the one for the Enemy: public class enemyhealth : MonoBehaviour { public int health = 100; // Use this for initialization void Start () { } // Update is called once per frame void Update () { } void OnDamage(){ health--; if (health <= 0) { Destroy(gameObject); } } } Whats not clear to me aswell is, what type of Collider I should use (Box Collider, CapsuleCollider...) Or doesnt it makes a difference? As I understood, Rigidbody is used for an other "technic" to make damage, am I right?

Viewing all articles
Browse latest Browse all 4

Trending Articles