void OnTriggerStay(Collider other)
    {
        if (_delayTime <= 0)
        {
            if (other.attachedRigidbody)
            {
                ForceConditions fc = (ForceConditions)other.GetComponent(typeof(ForceConditions));
                if (fc)
                {
                    switch (_forceType)
                    {
                    case ForceType.Push:
                        if (fc.canPush())
                        {
                            Vector3 direction = Vector3.Normalize(other.transform.position - this.transform.position);
                            other.rigidbody.AddForce(direction * Mathf.Clamp(_currentMagnitude / Vector3.Magnitude(other.transform.position - this.transform.position), 0, _maxMagnitude), ForceMode.Impulse);
                            other.GetComponent <ForceConditions>().setPullable(true);
                            grenade_explosion.Play();
                        }
                        break;

                    case ForceType.Pull:
                        if (fc.canPull())
                        {
                            Vector3 direction = Vector3.Normalize(this.transform.position - other.transform.position);
                            other.rigidbody.AddForce(direction * Mathf.Clamp(_currentMagnitude / Vector3.Magnitude(this.transform.position - other.transform.position), 0, _maxMagnitude), ForceMode.Impulse);
                        }
                        break;

                    case ForceType.Lift:
                        if (fc.canPush())
                        {
                            other.rigidbody.AddForce(Vector3.up * Mathf.Clamp(_currentMagnitude / Vector3.Magnitude(this.transform.position - other.transform.position), 0, _maxMagnitude), ForceMode.Impulse);
                        }
                        break;
                    }
                }
            }
        }
        else
        {
            _delayTime -= Time.deltaTime;
        }
    }
Ejemplo n.º 2
0
 void OnCollisionEnter(Collision col)
 {
     if (!hasCollided && col.rigidbody)
     {
         float velocity = col.rigidbody.velocity.sqrMagnitude;
         if (velocity > threshold)
         {
             ForceConditions fc = this.GetComponent <ForceConditions>();
             if (fc && (fc.canPull() || fc.canPush()))
             {
                 this.gameObject.SetActive(false);
                 fractureSet.gameObject.SetActive(true);
                 hasCollided = true;
             }
         }
     }
 }