- Home /
This question was
closed Dec 28, 2014 at 02:45 PM by
T-D-M-3 for the following reason:
I found the problem within My health Script
Question by
T-D-M-3 · Dec 28, 2014 at 02:24 PM ·
javascriptdamagesendmessagemelee
Repeating Damage sendMessage
So i have this Melee Damage Script that when it collides with an object it sends a message to deal 5 damage. The Problem i have is that it collides and sends 5 damage, but then continues to do the 5 damage every frame. Is there Any way to fix this?
here are the scripts for the melee damage and the damage receiver, Both Javascript
Damage Script:
var Damage : int = 5;
function Start () {
}
function Update () {
}
function OnTriggerEnter(hit:Collider){
hit.transform.SendMessage("Damage",Damage, SendMessageOptions.DontRequireReceiver);
Debug.LogError("Impact");
}
Damage Reciver:
var HealthScript : AiHealth;
var HitEffect : Transform;
var Point : Transform;
function Damage(Damage:int){
HealthScript.Health -= Damage;
var GotHit : Transform = Instantiate(HitEffect, Point.position,
Point.rotation);
}
function Start () {
}
function Update () {
}
Comment
Best Answer
Answer by Maurice_B · Dec 28, 2014 at 07:53 PM
you cannot send extra data through sendmessage. this may help:
var Damage : int = 5;
var receiver : reciverscriptnamehere;//the name of your reciever.js.
function Start () {
}
function Update () {
}
function OnTriggerEnter(hit:Collider){
receiver = hit.gameObject.GetComponent(recieverscriptnamehere);//assign the reciever a script.
//hit.transform.SendMessage("Damage",Damage, SendMessageOptions.DontRequireReceiver); not working;
receiver.Damage(Damage);
Debug.LogError("Impact");
}
hope that works for you.(code may need correcting capitals I don't have uity on right now.)