How to deal damge with a rigidbody(projectile), and whats the code for it.
There is no magical “add damage” function… you need to do these things yourself, because there are a thousand and one million ways to do it with different effects. Also, ‘health’ and ‘damage’ are just variables stored somewhere.
- when should the damage be dealt (probably OnCollisionEnter)
- to who should the damage be dealt (probably what you collide with)
if my assumptions above are correct, you’ll want to use OnCollisionEnter()
var damage : float;
var player : Collider;
function OnCollisionEnter( col : Collision )
{
if( col.collider == player )
player.gameObject.GetComponent.< playerHealthScript >().health -= damage;
}
this assumes you have a script attached to your player named playerHealthScript with the variable health.
the reason I answered this lazy and uninformed question is because it’s your first time on this site. In the future, please think about what you want to achieve, break it down and search how to do each little thing.