示例#1
0
        private void FixedUpdate()
        {
            bool hitted = Physics.Raycast(transform.position, Direction, out RaycastHit rayCastHit, 3f);

            if (hitted)
            {
                hitted = true;
                BehaviourSurfaceHit behaviourSurfaceHit = GetBehaviourSurfaceHit(rayCastHit.transform.gameObject);

                if (behaviourSurfaceHit)
                {
                    behaviourSurfaceHit.ShowDecal(rayCastHit.point, rayCastHit.normal);
                    behaviourSurfaceHit.ShowHitEffect(rayCastHit.point, rayCastHit.normal);
                }

                if (rayCastHit.rigidbody != null)
                {
                    rayCastHit.rigidbody.AddForce(-rayCastHit.normal * ImpactForce, ForceMode.Force);
                }
                Health health = rayCastHit.transform.gameObject.GetComponent <Health>();
                if (health != null)
                {
                    health.TakeDamage(Weapon.Damage, this.gameObject);
                }
            }

            if (!hitted)
            {
                transform.position += transform.forward * BulletSpeed * Time.fixedDeltaTime;
            }
            else
            {
                Destroy(this.gameObject);
            }
        }
示例#2
0
        private BehaviourSurfaceHit GetBehaviourSurfaceHit(GameObject gameObject)
        {
            BehaviourSurfaceHit found;
            BehaviourSurfaceHit behaviourSurfaceHit = gameObject.GetComponent <BehaviourSurfaceHit>();

            found = behaviourSurfaceHit != null ? behaviourSurfaceHit : gameObject.GetComponentInParent <BehaviourSurfaceHit>();

            return(found);
        }