In MisterNinjas fps tutorial he shows how to get the player to damage and all but I can't figure out how to make the enemy do damage to the player
Code:
#pragma strict
var Health = 100;
function ApplyDammage (TheDammage : int)
{
Health -= TheDammage;
if(Health <= 0)
{
Dead();
}
}
function Dead()
{
Destroy (gameObject);
}
Code:
NAMED PlayerHealth
var pHealth = 100;
function pApplyDamage (pTheDammage : int)
{
pHealth -= pTheDammage;
if(pHealth <= 0)
{
pDead();
}
}
function pDead()
{
Destroy (gameObject);
}
Code:
var pDamage = 100;
function OnCollisionEnter (info : Collision)
{
info.transform.SendMessage("pApplyDamage", pDamage, SendMessageOptions.DontRequireReceiver);
}
Code:
public int Damage = 10;
RaycastHit hit;
Ray ray;
if (Physics.Raycast(transform.position, Vector3.forward, out hit, 250f))
{
Debug.DrawLine(transform.position, hit.point, Color.red, 2f);
if(hit.collider.tag == "Player")
hit.collider.GetComponenet<HealthScript>().Health -= Damage;
}
|
|