- Home /
Need to Find the Radius of an Object?
Hi there,
I'm trying to get the radius of two objects, so I did this:
float expandedRadius = (obstacle.transform.GetComponent<SphereCollider>().radius) + (SphereCollider.radius);
But that gives me an error: 'An object reference is required to access not static member'
I'm looking for a fix or better alternative
Note: I'm working in C#
Answer by Mikilo · Feb 28, 2013 at 09:40 AM
Hi!
You can't access the radius with the class name, like here "SphereCollider.radius". You need to get the component of the second SphereCollider and then access ".radius". Like you did for the first component.
Good luck dude.
So how do I get the radius of the object the script is attached to?
this.SphereCollider.radius or something similar?
Which object do you want to compare? Yourself and another? If yes, try this.GetComponent().radius ins$$anonymous$$d of your static access.
Perfect, I assumed there was a simpler way that's all :/
No problem guy. =D But your way to do that, was not... Hum... Logical. Don't use static if you don't understand its meaning.
Answer by steakpinball · Feb 28, 2013 at 10:42 AM
Use GetComponent()
the access the SphereCollider
.
float totalRadius = other.GetComponent<SphereCollider>().radius + GetComponet<SphereCollider>().radius