Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by tag-94 · Nov 19, 2015 at 09:12 PM · uibuttoncanvasimage

How to have get button display a raw image?

Hi, currently I'm trying to get a button to display a raw image. I have the game objects set-up in the canvas I just don't know how to get the image to be invisible when the scene loads and then when the button is clicked to have the image appear.

For context this is for a character selection screen and I'm wanting the image of the player character to display when the character head shot is clicked on.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Dinosaurs · Nov 19, 2015 at 11:31 PM

Disable the gameObject with the image, and have the button activate it when clicked.

gameObject.SetActive(true);

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image tag-94 · Nov 19, 2015 at 11:51 PM 0
Share

I'm completely new to coding do you care to elaborate a bit more, please.

avatar image
0

Answer by SeasiaInfotechind · Nov 20, 2015 at 05:39 AM

Hi, If I have understood your problem correctly, solution is below:

 using UnityEngine;
 using System.Collections;
 using UnityEngine.UI;
 
 public class abc : MonoBehaviour {
     public Button xyz; // button to be clicked
     public Sprite change_texture; // texture you want to assign on button click
     // Use this for initialization
     void Start () {
 
     }
 
     // Update is called once per frame
     public void ButtonClicked ()
     {
         xyz.GetComponent<Image>().sprite = change_texture; // on clicking button sprite would change
     }
 }


Also don't forget to assign button function to be called on buttonclick from inspector.ScreenShot is attached. Script is attached to main camera.alt text

I hope your problem gets solved.Have a good Day!!


screen-shot-2015-11-20-at-110102-am.png (299.6 kB)
Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image tag-94 · Nov 20, 2015 at 04:30 PM 0
Share

Hi, first of all thanks for your help.

I have a couple of queries, I'm unsure where to put in the specific names of the objects and images in my project.

For context these are the names of the items I'm using.

Button to be clicked : Es

UI Raw Image (place where I want to image to be displayed) : EsFull

Image I want displayed : EsmeraldaFull

From the code you gave me this is what I have so far :

 using UnityEngine;
 using System.Collections;
 using UnityEngine.UI;
 
 public class ShowPlayerCharacter : $$anonymous$$onoBehaviour {
     public Button Es; // button to be clicked
     public Sprite EsmeraldaFull; // texture you want to assign on button click
     // Use this for initialization
     void Start () {
         
     }
     
     // Update is called once per frame
     public void ButtonClicked ()
     {
         Es.GetComponent<Image>().sprite = EsmeraldaFull; // on clicking button sprite would change
     }
 }



Also I can see that you placed the script on the camera, is there any specific options that I need to select on the camera to get the script to work.

Thanks again.

avatar image SeasiaInfotechind tag-94 · Dec 07, 2015 at 07:16 AM 0
Share

Hi, Were you able to make it work? Its not necessary to place your script on camera.You can place it on any object and drag drop that object on button Onclick property. In order to fetch the method you need to give reference of the script and its done by passing the object holding the script. So here my script was attached to camera thats why i dragged camera on Onclick property of button. If you will select camera and check inspector you will find the script attached .You only need to drag drop all the reference. eg: In option showing EsmeraldaFull , drag image from assets . Feel free to ask if any doubts.

avatar image
0

Answer by superhero02 · Jun 25, 2017 at 09:04 AM

When I Put characters in rawimage button how can you do levelmanager and character select at the same time

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Button becomes unclickable if it is in the panel 0 Answers

Unable to make animations for UI Image 2 Answers

Share button AR 0 Answers

UI buttons don't work with Canvas Render Mode: Screen Space - Camera. 2 Answers

Changing the image of a button with a script 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges