Exemplo n.º 1
0
    private void OnDrawGizmos()
    {
        if (Time.time > ExplosionTriggerTime)
        {
            float ExplosionTime = Time.time - ExplosionTriggerTime;
            float Radius        = ExplosionRadius.Evaluate(ExplosionTime);
            float Force         = ExplosionForce.Evaluate(ExplosionTime);

            Gizmos.color = new Color(0.5f + Force / 500, 0.5f - Force / 500, 0, Mathf.Clamp(Mathf.Abs(Force) / 1000, 0.1f, 0.75f));
            Gizmos.DrawSphere(transform.position, Radius);
        }
    }
Exemplo n.º 2
0
    private void FixedUpdate()
    {
        if (Time.time > ExplosionTriggerTime)
        {
            if (Time.time > ExplosionEndTime)
            {
                Destroy(this);
            }

            float ExplosionTime = Time.time - ExplosionTriggerTime;
            float Radius        = ExplosionRadius.Evaluate(ExplosionTime);
            float Force         = ExplosionForce.Evaluate(ExplosionTime);

            if (Radius <= 0)
            {
                return;
            }

            Collider[] HitColliders = Physics.OverlapSphere(transform.position, Radius);

            foreach (Collider HitCollider in HitColliders)
            {
                if (HitCollider.gameObject == this.gameObject)
                {
                    continue;
                }
                Rigidbody Body = HitCollider.GetComponent <Rigidbody>();
                if (Body == null)
                {
                    continue;
                }
                float BodyDistance = Vector3.Distance(Body.transform.position, transform.position);

                Body.AddExplosionForce(Force * ForceFalloff.Evaluate(BodyDistance / Radius), ExplosionLocation, 0.0f, 0.0f, ForceMode.Force);
            }
        }
    }