Yes I do realize this question has been asked many time before. but i have never found one that fits my needs, and yes i am new and i am taking this project 1 step at a time
-
Enemy Object name = enemy
-
player is Main Camera
-
Health Script
var Health = 100;
function ApplyDammage (TheDammage : int)
{
Health -= TheDammage;if(Health <= 0) { Dead(); }
}
function Dead()
{
Destroy (gameObject);
} -
Raycast Shooting Script
var Effect : Transform;
var TheDammage = 100;function Update () {
var hit : RaycastHit; var ray : Ray = Camera.main.ScreenPointToRay(Vector3(Screen.width*0.5, Screen.height*0.5, 0)); if (Input.GetMouseButtonDown(0)) { if (Physics.Raycast (ray, hit, 100)) { var particleClone = Instantiate(Effect, hit.point, Quaternion.LookRotation(hit.normal)); Destroy(particleClone.gameObject, 2); hit.transform.SendMessage("ApplyDammage", TheDammage, SendMessageOptions.DontRequireReceiver); } }
}
-
Current attempt that dont work
var health = 4;
var damage = 1;
var wait_time = 2;
var lock = 0;function OnCollisionEnter(hit: Collision){ if(hit.gameObject.tag == "enemy" && lock == 0) { hit.transform.SendMessage("ApplyDammage", 100, SendMessageOptions.DontRequireReceiver); } }