That is a good question. I am not sure what is wrong.
I will tell you, though, that I think you should step away from OnGUI. That is old and you should use the new UI stuff.
And if your goal is to find out if the mouse is inside a rect in the new UI stuff, it will be pretty easy.
I agree with the switch to the new ui system as well. But, that aside, when posting an error it’s best to give the full error and what line it points to, otherwise we’re just guessing. Luckily I know what this error is, just not which line.
I mean the full start function. I ask because this:
suggests to me that you may have misnamed the Start() function (not capitalizing it). If it’s not capitalized it won’t run, and that would lead to the error you’re seeing.
Can you even call ‘Event.current’ from Update()? I’m not sure…
Are these rects always in the same place? If you don’t go the new UI route (reconsider, really think about it :))
You can just add all of the rects on Start() .
Anyways, back to Event.current. You can use: Input.MousePosition instead of Event.current
I don’t really understand what you mean by create the image. Do you mean instantiate an Image UI element to add to a scroll view? And if the list is fixed (not changing), you can create it all in the inspector.
Position depends on how you want the scroll view setup.
“problem with scrollview” is too vague…
The list is not fixed. I’m trying to create an inventory system. I need to add 30 images (50x50) in a panel which is a ScrollRect. But I don’t manage to do that…
Yep yep. so that’s no problem. Maybe you want to add a GridLayout to your scroll view. Whenever you add images, you can use code very similar to what I wrote above. Is this making any sense?
No need to add “Image i = c.AddComponent()” … no need for that part. A rect transform (panel) already has an image & that is what the error is telling you.
Erase that line & then try again