I have a cube object named car and four cylinders attached to the car object as wheels. The cylinders are children of the car. Each cylinder has a wheel collider attached to it. I want to access WheelCollider component of these cylinders for which I have the following code:
void Update()
{
steer = Input.GetAxis("Horizontal") * maxSteer;
GetCollider(0).steerAngle = steer;
GetCollider(1).steerAngle = steer;
}
WheelCollider GetCollider(int n){
return wheels[n].gameObject.GetComponent("WheelCollider") ;
}
This throws the following error:
Cannot implicitly convert type ‘UnityEngine.Component’ to ‘UnityEngine.WheelCollider’. An explicit conversion exists (are you missing a cast?)
What am I missing here. Thanks in advance.