- Home /
Question by
CamoLeopard · Mar 02, 2015 at 01:41 PM ·
components
Define game object.
I am trying to define a gameobject and then enable/disable components, my script goes as follows:
using UnityEngine;
using UnitySampleAssets.CrossPlatformInput;
namespace UnitySampleAssets.Vehicles.Car
{
[RequireComponent(typeof (CarController))]
public class CarUserControl : MonoBehaviour
{
private CarController car; // the car controller we want to use
private Object wfr;
private Object wfl;
private Object wbl;
private Object wbr;
public Transform to;
public float speed = 0.1F;
public Transform from;
private void Awake()
{
// get the car controller
car = GetComponent<CarController>();
wfr = GameObject.Find("/Car/WheelHubFrontRight");
wfl = GameObject.Find("/Car/WheelHubFrontLeft");
wbr = GameObject.Find("/Car/WheelHubRearRight");
wbl = GameObject.Find("/Car/WheelHubRearLeft");
}
public void Update()
{
if (Input.GetKeyDown ("h")) {
((MonoBehaviour)wfr.GetComponent("Lerp")).enabled = true;
}
}
public void FixedUpdate()
{
// pass the input to the car!
float h = CrossPlatformInputManager.GetAxis("Horizontal");
float v = CrossPlatformInputManager.GetAxis("Vertical");
car.Move(h, v);
}
}
}
Any help?
Comment
Line 33: Remove Parantheses
Even better, use the generic version:
wfr.GetComponent<Lerp>().enabled = true;
Sorry I have it working now, I had defined them as an object not a gameobject. Thanks alot!
Your answer
![](https://koobas.hobune.stream/wayback/20220613184739im_/https://answers.unity.com/themes/thub/images/avi.jpg)