Question by
dandelo99 · Jan 17, 2016 at 05:03 PM ·
unity 5constantforce
new constant force in unity 5
if (isUnderwater==true && Input.GetKey(KeyCode.E))
{
constantForce.relativeForce = Vector3 (0,-200,0);
}
else
{
constantForce.relativeForce = Vector3 (0,0,0);
}
if (isUnderwater==true && Input.GetKey(KeyCode.Q))
{
constantForce.relativeForce = Vector3 (0,200,0);
}
else
{
constantForce.relativeForce = Vector3 (0,0,0);
}
i have this code piece but im taking this error; 'UnityEngine.Component.constantForce' is obsolete. Property constantForce has been deprecated. Use GetComponent() instead. (UnityUpgradable) i couldn't fix this can someone help.
Comment
Best Answer
Answer by hexagonius · Jan 17, 2016 at 06:15 PM
All the shorthands except for "transform" have been deprecated. You access all other components by "GetComponent()"
if (isUnderwater==true && Input.GetKey(KeyCode.E))
{
GetComponent<ConstantForce>().relativeForce = Vector3 (0,-200,0);
}
else
{
GetComponent<ConstantForce>().relativeForce = Vector3 (0,0,0);
}
if (isUnderwater==true && Input.GetKey(KeyCode.Q))
{
GetComponent<ConstantForce>().relativeForce = Vector3 (0,200,0);
}
else
{
GetComponent<ConstantForce>().relativeForce = Vector3 (0,0,0);
}
Thank you i looked for this but couldn't find clearly like this answer
Your answer
![](https://koobas.hobune.stream/wayback/20220612060543im_/https://answers.unity.com/themes/thub/images/avi.jpg)