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#
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.
Use GetComponent() the access the SphereCollider.
GetComponent()
SphereCollider
float totalRadius = other.GetComponent<SphereCollider>().radius + GetComponet<SphereCollider>().radius