|
|
|
|
|
|
[ExecuteAlways] |
|
|
|
public class RigidbodyAction : ActionBase |
|
|
|
{ |
|
|
|
public bool ApplyOnInstigator = false; |
|
|
|
[HideIf("ApplyOnInstigator")] |
|
|
|
public Rigidbody m_Rigidbody; |
|
|
|
[OnValueChanged("OnParameterTypeChanged")] |
|
|
|
public RigidbodyActionType actionType; |
|
|
|
|
|
|
|
|
|
|
public override void Execute(GameObject instigator = null) |
|
|
|
{ |
|
|
|
if (m_Rigidbody == null) |
|
|
|
Rigidbody target = m_Rigidbody; |
|
|
|
|
|
|
|
if (ApplyOnInstigator) |
|
|
|
target = instigator.GetComponent<Rigidbody>(); |
|
|
|
|
|
|
|
if (target == null) |
|
|
|
{ |
|
|
|
Debug.LogWarning("Could not apply RigidbodyAction to null Rigidbody"); |
|
|
|
} |
|
|
|
|
|
|
|
switch (actionType) |
|
|
|
{ |
|
|
|
|
|
|
m_Rigidbody.AddForce(direction, forceMode); |
|
|
|
target.AddForce(direction, forceMode); |
|
|
|
m_Rigidbody.AddRelativeForce(direction, forceMode); |
|
|
|
target.AddRelativeForce(direction, forceMode); |
|
|
|
m_Rigidbody.AddTorque(direction, forceMode); |
|
|
|
target.AddTorque(direction, forceMode); |
|
|
|
m_Rigidbody.AddRelativeTorque(direction, forceMode); |
|
|
|
target.AddRelativeTorque(direction, forceMode); |
|
|
|
m_Rigidbody.AddExplosionForce(explosionForce, explositonPosition, explosionRadius, 0, forceMode); |
|
|
|
target.AddExplosionForce(explosionForce, explositonPosition, explosionRadius, 0, forceMode); |
|
|
|
m_Rigidbody.Sleep(); |
|
|
|
target.Sleep(); |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|