private void OnProjectileHit(ProjectileHitInfo hit) { var d = GetComponent <Damagable> (); if (d != null) { d.Damage(hit.projectile.damage, hit.projectile.playerShooter); } }
// Update is called once per frame void Update() { this.timeAlive += Time.deltaTime; if (this.timeAlive > this.lifeTime) { this.MyDestroy(); return; } // Rigidbody body = GetComponent<Rigidbody> (); if (this.isServer) { RaycastHit hitInfo; if (Physics.Raycast(transform.position, transform.forward, out hitInfo, this.velocity * Time.deltaTime * 1.1f)) { bool ignoreCollision = false; if (this.timeToAvoidCollisionWithPlayerShooter != 0) { if (this.timeAlive < this.timeToAvoidCollisionWithPlayerShooter) { // check if we hit player shooter object if (this.playerShooter != null) { Player player = PlayerManager.GetPlayerByGameObject(hitInfo.transform.gameObject); if (player == this.playerShooter) { // we hit player shooter object // we should ignore this collision ignoreCollision = true; } } } } if (!ignoreCollision) { // Debug.Log ("Bullet hit object " + hitInfo.transform.gameObject.name + ", distance " + hitInfo.distance); if (this.shouldApplyDamageOnHit) { // create explosion if (this.explosionPrefab != null) { this.explosionPrefab.InstantiateWithNetwork(hitInfo.point, Quaternion.identity); } // notify game object that it was hit ProjectileHitInfo projectileHitInfo = new ProjectileHitInfo(); projectileHitInfo.projectile = this; projectileHitInfo.hit = hitInfo; hitInfo.transform.gameObject.BroadcastMessage("OnProjectileHit", projectileHitInfo, SendMessageOptions.DontRequireReceiver); } this.MyDestroy(); return; } } } if (this.isServer) { this.transform.position += this.transform.forward * this.velocity * Time.deltaTime; } if (this.hideOnStart) { if ((this.transform.position - this.startPosition).sqrMagnitude > 1 * 1) { this.GetComponent <Renderer> ().enabled = true; if (this.halo != null) { this.halo.enabled = true; } } } }