示例#1
0
        public virtual void FireProyectile(RaycastHit AimRay)
        {
            float percent = Random.Range(0, 1);

            Vector3 AimDirection = (AimRay.point - transform.position).normalized;

            if (C_ReduceAmmoAfterShoot != null)
            {
                StopCoroutine(C_ReduceAmmoAfterShoot);
            }
            C_ReduceAmmoAfterShoot = ReduceAmmoAfterShoot();
            StartCoroutine(C_ReduceAmmoAfterShoot);

            OnFire.Invoke(AimDirection);

            if (AimRay.transform)                                                                                       //If the AIM Ray hit something
            {
                var interactable = AimRay.transform.GetComponent <IInteractable>();
                interactable?.Interact();

                AffectStat.Value = Random.Range(MinDamage, MaxDamage);
                AffectStat.ModifyStat(AimRay.transform.GetComponentInParent <Stats>());

                Damager.SetDamage(AimRay.normal, AimRay.transform, transform);

                if (AimRay.rigidbody)                                                                                          //If the thing we hit has a rigidbody
                {
                    AimRay.rigidbody.AddForceAtPosition(AimDirection * Mathf.Lerp(MinForce, MaxForce, percent), AimRay.point); //Apply the force to it
                }

                BulletHole(AimRay);

                OnHit.Invoke(AimRay.transform);  //Invoke OnHitSomething Event
            }
        }
示例#2
0
        internal void SetDamageStuff(Vector3 OtherHitPoint, Transform other)
        {
            var Root = other.root;

            if (Root == transform.root)
            {
                return;                                               //if Im hitting myself
            }
            //Mount montura = other.GetComponentInParent<Mount>();
            //Mount OwnerMount = Owner.GetComponent<MRider>()?.Montura;
            //if (OwnerMount != null && montura == OwnerMount) return;          //Do not Hit your Mount

            if (!MalbersTools.Layer_in_LayerMask(other.gameObject.layer, HitLayer))
            {
                return;                                                                              //Just hit what is on the HitMask Layer
            }
            Debug.DrawLine(OtherHitPoint, meleeCollider.bounds.center, Color.red, 3f);

            if (canCauseDamage && !AlreadyHitted.Find(item => item == Root))                        //If can cause damage and If I didnt hit the same transform twice
            {
                AlreadyHitted.Add(Root);

                Rigidbody OtherRB = other.GetComponentInParent <Rigidbody>();

                var interactable = other.GetComponent <IInteractable>();
                interactable?.Interact();

                if (OtherRB)
                {
                    OtherRB.AddExplosionForce(MinForce * 50, OtherHitPoint, 5);
                }


                var mesh      = Root.GetComponentInChildren <Renderer>();
                var TargetPos = Root.position;
                if (mesh == null)
                {
                    TargetPos = mesh.bounds.center;
                }

                Vector3 direction = (OtherHitPoint - TargetPos).normalized;

                AffectStat.Value = Random.Range(MinDamage, MaxDamage);
                AffectStat.ModifyStat(Root.GetComponentInChildren <Stats>());                     //Affect Stats


                Damager.SetDamage(direction, Root, transform);

                PlaySound(3);     //Play Hit Sound when get something

                OnHit.Invoke(other.gameObject);

                if (!meleeCollider.isTrigger)
                {
                    meleeCollider.enabled = false;
                }
            }
        }