- Home /
Add gameObject/transform to script component slot with editor
Hi, I want to be able to fill Transform and gameobjects in script components slots with a seperate Editor script. I assume this would be the same as filling the slots at runtime.
pupilCTRL is the script attached to the eyeInnerR asset. In this script component there is an empty transform slot by the name of Other. This is where I want to drop the gameobject Cube.
Any help would be appreciated
{
GameObject PupilRCTRL = GameObject.Find("eyeInnerR");
Component PupilRCTRLCheck = PupilRCTRL.GetComponent<pupilCTRL>();
if (PupilRCTRL != null && PupilRCTRLCheck == null)
{
GameObject tester = GameObject.Find("Cube");
PupilRCTRL.GetComponent<pupilCTRL>().other.Add(tester);
}
}
Answer by BastianUrbach · Oct 12, 2018 at 12:11 PM
So other is just a public field like this (which appears as a slot in the inspector)?
public Transform other;
In that case, you can just write:
PupilRCTRL.GetComponent<pupilCTRL>().other = tester.transform;
Awesome!! Thanks coeusueoc.
I was getting Error CS0305 but just need to add the script component. So...
PupilRCTRL.GetComponent<pupilCTRL>().other = tester.transform;
Its working perfectly thanks again, I was going about it all wrong
Oh right, I actually wrote that but it was treated as a markup tag.