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
1
Question by ltrout1999 · Dec 13, 2015 at 09:43 PM · uiimage

How to show image when button is pressed?

I created a simple UI Button called Options and I want to show an image when that button is pressed. How would I do this? This is the code I have, and it's not showing anything when I click on that button.

 using UnityEngine;
 using System.Collections;
 
 public class Options : MonoBehaviour {
 
     public Texture2D imgOptions;
 
     public void ChangeImage() {
         imgOptions = (Texture2D)Resources.Load("Images/PNGs/Menu_Options.png");
     }
 }
 
Comment
Add comment · Show 2
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 ltrout1999 · Dec 13, 2015 at 10:33 PM 0
Share

@dhore . Could you help me?

avatar image dhore ltrout1999 · Dec 14, 2015 at 01:19 AM 0
Share

Sure thing :)

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by dhore · Dec 14, 2015 at 01:18 AM

A Texture2D is only a texture, it won't render to the screen by itself. What you're looking for is "Hierarchy > Create > UI > Image" and that will have an component called "Image (Script)" which you can give a "Source Image" to. Then just enable/disable that Image GameObject to show/hide the image on the screen.

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 ltrout1999 · Dec 14, 2015 at 01:28 AM 0
Share

Okay I just ended up creating an entirely new scene and using buttons to navigate between them. By any chance would you know how to create a basic AI that follows the user and shoots at them?

avatar image dhore ltrout1999 · Dec 14, 2015 at 01:47 AM 0
Share

I'd suggest learning about Unity's Nav$$anonymous$$esh for AI pathfinding. There's a good Tutorial here.

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

43 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Scaling an image sent to UI Image 0 Answers

The problem with the UI image. 0 Answers

Displaying GUIText on top of Unity UI Image? 0 Answers

RectTransform offset renders wrong (UnityAndroid) 0 Answers

How to make an object the root of a prefab, or remove the canvas that is set as the root of a prefab 0 Answers


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