Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change button image in Unity 3D

I'm a Unity nob, so please don't flame me for this question.

I'm trying to change a simple UI button to look like a Play button (via simple Play PNG image), I see that the Button have a Source Image under the Image script, but as far as I can see I must select a Sprite.

How can I create a Sprite from a PNG Image?

like image 819
David Avatar asked Mar 12 '17 08:03

David


People also ask

How to add a texture to a PNG file in Unity?

Import your PNG by drag your file to the Project panel, Unity will automatically generate texture for you. Click on that file, The Inspector panel will show texture's Import setting. In Inspector, Choose texture type as Sprite (2D and UI), Hit Apply at the bottom. In Project Panel, Drag this texture to your Source Image under Image Script

Is it possible to use image in Unity UI?

Unfortunately, unity ui is full of such pitfalls and it's api is totally counter-intuitive, so you have to be careful and check the docs regularly Show activity on this post. You can also just use Image if you are in Unity 2017.3 (not sure if this works for older versions). For example: Works great for me. Show activity on this post.

How do I change the image of a button?

To change the Image from a Button, don't use GetComponent<Image> () as you can potentially get another Image component that does not belong to the button. It can also return null if the object is disabled. Use the Button.image.sprite or Button.image.overrideSprite variable instead. It really doesn't matter which one is used.

How to change the default skybox in Unity?

Once the images are in place, go to lighting manager window and change the default skybox to the new material that you just created. Here is the final result of some skybox materials for your reference. To play around with different skybox images, you can use this asset available for free on Unity store.


1 Answers

Unity's sprite is a kind of Texture.

  1. Import your PNG by drag your file to the Project panel, Unity will automatically generate texture for you.

  2. Click on that file, The Inspector panel will show texture's Import setting. enter image description here

  3. In Inspector, Choose texture type as Sprite (2D and UI), Hit Apply at the bottom. enter image description here

  4. In Project Panel, Drag this texture to your Source Image under Image Script

like image 132
b.ben Avatar answered Sep 21 '22 13:09

b.ben