- Home /
Question by
rainbow_design · Jan 16, 2016 at 01:28 AM ·
c#unity 5getcomponent
Getcomponent what do i wrong?
i want to change the Appearance of the button when its not clicked. But it seems to go into the wrong image.
public static GameObject obuild(String name, GameObject menuprefab, string spri, Vector3 position, Vector2 scales) {
GameObject fmitem = Instantiate2(menuprefab);
fmitem.GetComponent<Image> ().overrideSprite = (Sprite) Resources.Load (spri);
fmitem.name = name;
fmitem.transform.localScale = (scales);
fmitem.transform.localPosition = position;
return fmitem;
}
unity.png
(22.0 kB)
Comment
You sure it's not just fmitem.GetComponent().image = blah blah?
Best Answer
Answer by Positive7 · Jan 16, 2016 at 01:28 PM
fmitem.GetComponent<Image> ().overrideSprite = Resources.Load<Sprite>(spri);
thankyou i think i had a mistake there too but the real problem is that i have the path not correct. i accept it as answer anyways.