#Bad / dumb code
1 messages · Page 1 of 1 (latest)
Because you're calling GetComponent twice
on the same thing
use TryGetComponent instead
can you explain more please
Which part, why it's bad? Or do you mean an example for TryGetComponent
The docs have one https://docs.unity3d.com/ScriptReference/Component.TryGetComponent.html
if i use try get component then how would call the method that is in component?
The docs give an example for that
if (TryGetComponent(out HingeJoint hinge))
{
hinge.useSpring = false;
}
i do not quite understand the parameter that is given to this function like out thing cause that is used in raycast i think
ok what method would be better if there is no such thing as trygetcomponent in above code
There is tho
assume that its not available i mean
Why would I assume that
You're literally already calling GetComponent. If you can call GetComponent, you can call TryGetComponent
alright thanks for your time and help @queen spear
@fresh fulcrum appreciate it guys