I’am having a hard time finding a way to create a custom button via script. I know you can create a new guiskin in the assets menu, but I want to do it dynamically.
Let’s say for example that a player will have a red button and another a random colored button, And the style will have to be done via script depending on the game circunstance.
Use a different texture for your button style. The textures in the default GUI skin use rounded corners.
If you know the colors ahead of time, in your script you could define a public array of Texture2D’s. Then create separate textures for each color, and in the inspector assign the textures to the array. When you set up the GUI style, randomly choose one of the textures from the array.
If you’ll only have one button of this type on the screen, you can use SetPixels() to change the texture directly. If you have multiple randomly-colored buttons onscreen, you’ll want to create a texture for each and use SetPixels() to set their colors.