Hi, im trying to solve this for three days by now, so i ask here:
I have a multiplayer game with working authoritative moving players. Whats also working well is network instantiating fireballs done by server on players request. When a fireball collides something, it succesfully Network.destroys itself by function OnCollisionEnter and spawns my explosion prefab.
But what i need it to do is that when the fireball hits “something” tagged as Player, he has to lose 1 health.
I have tried around a hundred ways to make this happen, but not a single on was working.
Can anybody help me with this problem?
This is my working code attached to fireball that destroys the fireball itself:
function OnCollisionEnter(collision : Collision) {
// Rotate the object so that the y-axis faces along the normal of the surface
var contact : ContactPoint = collision.contacts[0];
rot = Quaternion.FromToRotation(Vector3.up, contact.normal);
pos = contact.point;
if(Network.isServer){
Network.Instantiate(explosionPrefab, pos, rot, 0);
Network.Destroy (gameObject);
}
}
I have tried, for example to put into this code
if(collision.gameObject.tag == "Player"){
collision.gameObject.SendMessage("ApplyDamage");
}
but it worked in one from five shots, or to put into Playerscript the OnCollisionEnter and if the tag is “Fireballshot”, gave me pretty much the same result.
I also tried to try a trigger attached on the fireball and function OnTriggerEnter in the Playerscript and many other ways and im just desperate.
HELP!