I’m working on a multiplayer game were you can shoot projectiles at other players. I however ran into a problem. When the player clicks a button a projectile is instantiated in the game and travels in the direction the camera was facing, but when it collides with an enemy player it deals damage twice. I tried solving the problem for a couple of days now but with no luck. Could anyone please tell me what I’m doing wrong?
#pragma strict
var onHitEffect : GameObject;
var damadge : int;
var speed : float = 50;
var size : Vector3;
var directionDistance : float = 50;
var directionCurve : AnimationCurve;
var directionStrength : Vector2 = Vector2(0, 0);
var directionStrengthMulti : float;
var savedRot : Vector3;
@HideInInspector
var keepMoving : boolean = true;
@HideInInspector
var time : float;
@HideInInspector
var screenPos : Vector3;
@HideInInspector
var hit : boolean = false;
//////////////////// I left out the code that makes the projectile move forwards because it just takes up space and isn't the problem
function OnNetworkInstantiate (info : NetworkMessageInfo) {
if (networkView.isMine)
Debug.Log("New object instanted by me");
else
Debug.Log("New object instantiated by " + info.sender);
}
function OnCollisionEnter(collision : Collision) {
if (collision.gameObject.tag == "Player" networkView.isMine){ // Cheks if it hi a player an if the object belongs to us
var playerScript = collision.gameObject.GetComponent(Player);
playerScript.networkView.RPC("TakeDamadge", RPCMode.All, damadge); // tells everone to take damadge
//playerScript.TakeDamadge(damadge);
Debug.Log("Hit player for" + damadge);
}
if (onHitEffect){
var contact : ContactPoint = collision.contacts[0];
var rot = Quaternion.FromToRotation(Vector3.forward, contact.normal);
Instantiate(onHitEffect, contact.point, rot);
}
Destroy (gameObject);
}