unity object has component code example
Example 1: unity check if a gameobject has a component
if(gameObjectToCheck.GetComponent<Rigidbody>() != null) { //do something }
Example 2: unity try get component
using UnityEngine;public class TryGetComponentExample : MonoBehaviour
{
void Start()
{
if (TryGetComponent(out HingeJoint hinge))
{
hinge.useSpring = false;
}
}
}