Beispiel #1
0
        /// <summary>
        /// This method of shooting is a hybrid between the usage of the barrel orientation for hit detection,
        /// and the always-hit method. NPC's use this method to shoot at the player. Their bullets only hit
        /// if there is an unobstructed path between the gun of the NPC and the player's head.
        /// </summary>
        public void ShootAtPlayer()
        {
            PlayGunEffects();

            Transform playerEye = Player.Player.Instance.PlayerCameraEye;

            if (playerEye == null)
            {
                throw new NullReferenceException("Unable to locate player head, cannot shoot at player.");
            }

            RaycastHit hit;

            if (Physics.Linecast(RaycastObject.transform.position, playerEye.position, out hit))
            {
                if (hit.transform == playerEye)
                {
                    float damage = RNG.NextFloat(_minDamage, _maxDamage);
                    Player.Player.Instance.HandleHit(damage);
                }
                else
                {
                    HandleHit(hit);
                }

                // Adds shots to statistics
                ShowShots showShots = UnityEngine.Object.FindObjectOfType <ShowShots>();
                if (showShots != null)
                {
                    showShots.Save(new Shot(hit.transform.gameObject, RaycastObject.transform.position, this.gameObject.transform.GetComponentInParent <NPC>().gameObject, hit.point), false);
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Shoot the gun. Uses the gun orientation and physics engine to determine what it hit. Sends HitMessage to target.
        /// </summary>
        public virtual void Shoot()
        {
            IsPanicking.playerShot = true;
            PlayGunEffects();

            Vector3 barrelDirection = RaycastObject.transform.TransformDirection(Vector3.up);

            RaycastHit hit;

            if (Physics.Raycast(RaycastObject.transform.position, barrelDirection, out hit))
            {
                // Adds shots to statistics
                ShowShots showShots = UnityEngine.Object.FindObjectOfType <ShowShots>();
                if (showShots != null && ScenarioBase.Instance.Started)
                {
                    showShots.Save(new Shot(hit.transform.gameObject, RaycastObject.transform.position, RaycastObject, hit.point), true);
                }

                HandleHit(hit);
            }
        }