Exemplo n.º 1
0
        public void TakeDamage(DamageDataGPURaycast damage)
        {
            Health -= damage.DamageAmount;

            if (Health <= 0)
            {
                Destroy(gameObject);
            }
        }
Exemplo n.º 2
0
        protected virtual void shot(int button)
        {
            if (button == 0)
            {
                handsAnimator.Play("Shot", 0, 0);
                if (UseGPURaycast)
                {
                    GPURaycastDecalsTargetInfo hitInfo;
                    if (GPURaycast.RaycastToRegisteredTargets(Camera.main, Vector2.one / 2, out hitInfo))
                    {
                        var hittable = hitInfo.hittedRenderer.GetComponent <Hittable>();
                        if (hittable != null)
                        {
                            DamageDataGPURaycast damage = new DamageDataGPURaycast()
                            {
                                DamageAmount = Damage,
                                HitInfo      = hitInfo
                            };

                            hittable.TakeDamage(damage);
                        }

                        DecalReceiverHelper.SendGPURaycastInfo(hitInfo);
                    }
                }
                else
                {
                    Ray        r = new Ray(Camera.main.transform.position, Camera.main.transform.forward);
                    RaycastHit hitInfo;

                    if (Physics.Raycast(r, out hitInfo, 1000, ShotMask))
                    {
                        var hittable = hitInfo.collider.GetComponent <Hittable>();
                        if (hittable != null)
                        {
                            DamageDataPhysics damage = new DamageDataPhysics()
                            {
                                DamageAmount = Damage,
                                HitInfo      = hitInfo
                            };

                            hittable.TakeDamage(damage);
                        }

                        DecalReceiverHelper.SendPhysicsRaycastInfo(hitInfo);
                    }
                }
            }
            else if (button == 2)
            {
                handsAnimator.Play("Shot", 0, 0);
                GameObject projectileInstance = Instantiate(ProjectilePrefab, ProjectilePrefab.transform.position, ProjectilePrefab.transform.rotation);
                projectileInstance.transform.SetParent(null);
                projectileInstance.gameObject.SetActive(true);
            }
        }