- Home /
The question is answered, right answer was accepted
void OnCollisionEnter(Collider other) { if (Rigidbody.velocity.magnitude > 5) {...} - In "Rigidbody.velocity.magnitude" asks to give link to the object???
...
void OnCollisionEnter(Collider other) {
if (Rigidbody.velocity.magnitude > 5) {
if (other.gameObject.tag == "Contact") {
print ("contact");
GetComponent<Trigger> ().gameObject.SetActive (false);
}
}
}
In "Rigidbody.velocity.magnitude" asks to give link to the object. But script is already attached to an object, i don't understand
Answer by crohr · Jun 10, 2015 at 06:39 AM
You are trying to access velocity as if it were a static property. Try to use.
GetComponent<Rigidbody>().velocity.magnitude
Answer by fafase · Jun 10, 2015 at 06:36 AM
rigidbody not Rigidbody.
You can now close the question. :)
Rigidbody (uppercase) is the name of the component type. rigidbody (lowercase) is the instance of it. Additionally, in Unity 5, it would be used in the context:
if(GetComponent<Rigidbody>().velocity.magnitude > 5)
{
// ...
}
As an additional note, using "sqr$$anonymous$$agnitude > 25" would be a faster calculation to perform.
Indeed they removed the references (except transform) so you have to get your component.