- Home /
Cannot assign Public GameObject variable in Inspector...
I am creating a script that makes an object rotate after certain time has pass.
Code looks like this:
public GameObject Left01, Left02, Left03;
public float countdown = 4.0f;
void Update ()
{
countdown -= Time.deltaTime;
if (countdown <= 3.0f) {
Left01.transform.Rotate (new Vector3 (0, 10, 0) * Time.deltaTime);
}
if (countdown <= 2.0f) {
Left02.transform.Rotate (new Vector3 (0, 10, 0) * Time.deltaTime);
}
if (countdown <= 1.0f) {
Left03.transform.Rotate (new Vector3 (0, 10, 0) * Time.deltaTime);
}
}
}
The variable slots appear in the inspector no problem, but when I try to drag the object into the slot, nothing happens. The object is not recognized and I cannot drop in where it belongs.
Is the anything wrong with my object? Its being properly tagged.
I don't see any problem, try separate the object declaration one per line, i don't think it will be a problem.
I've declared properties like this all the time with no issue. Are you dropping a game object into those fields? Or an asset?
Answer by AurimasBlazulionis · Oct 28, 2016 at 08:47 PM
Try clicking the little circle button in the right of the variable and select the object you need from the whole list. You can search for the object there.
If that does not work, try declaring all variables in each line.
Answer by LinkNYC · Oct 29, 2016 at 05:56 PM
I end up making a prefab of each item and the. I was able to drop them in each box.
I am having the same problem and I don't see how making a prefab would help. I can't really do that in my case.