public virtual void Fire() { if (Cooldown.IsActive) { //Debug.Log(name + " is on cooldown.", this); return; } //Debug.Log("Fire " + name); if (Ammunition != null) { // Instantiate Projectile projectile = Instantiate(Ammunition, Muzzle.position, Muzzle.rotation); // Add force projectile.GetComponent <Rigidbody>()?.AddForce(GetComponentInParent <Rigidbody>().velocity *ParentVelocityInfluence + Muzzle.forward * ProjectileSpeed, forceMode); projectile.Owner = GetComponentInParent <Player>(); if (ServerBehaviour.HasActiveInstance()) { ServerBehaviour.Instance.projectiles.Add(projectile); } StartCoroutine(Cooldown.Start()); } }
protected virtual void Impact(Collision collisionData) { if (collisionData != null) { string output = ""; if (Owner != null) { if (!CanHitOwner) { if (collisionData.gameObject == Owner.gameObject) { Debug.Log(name + " can't hit owner " + Owner.name); return; } } output += Owner.name + " with "; } output += name; //Debug.Log(collisionData.gameObject.name + " was hit by " + output); Player playerHit = collisionData.gameObject.GetComponent <Player>(); if (playerHit != null) { //player.TakeDamage(Damage); if (Owner != null) { GameManager.Instance.PlayerTakesDamage(playerHit, Damage, Owner); } else { GameManager.Instance.PlayerTakesDamage(playerHit, Damage); } //player.Die(); } Health healthComponent = collisionData.collider.GetComponentInParent <Health>(); if (healthComponent != null) { healthComponent.UpdateValue(healthComponent.value - Damage); } } impactPosition = transform.position; hasImpacted = true; Explosive explosive = GetComponent <Explosive>(); if (explosive != null) { explosive.Explode(); } if (DisappearUponImpact) { if (ServerBehaviour.HasActiveInstance()) { ServerBehaviour.Instance.SendProjectileImpact(this); } //Debug.Log("Disappear"); gameObject.SetActive(false); } }
private void OnCollisionEnter(Collision collision) { Player player = collision.collider.attachedRigidbody?.GetComponent <Player>(); if (ServerBehaviour.HasActiveInstance() && player != null && player != this) { Debug.Log("Found server behaviour: " + ServerBehaviour.Instance.name, ServerBehaviour.Instance); ServerBehaviour.Instance.PlayerCollision(); } }