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 arjunh · Sep 19, 2016 at 05:03 AM · 3dunity5

i have used an image on my game how can i pop up a new image when the first image is clicked

instead of buttons i have used images..when one image is clicked a new one should popup, can any one provide some refferences

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

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by lawrence-parry · Sep 19, 2016 at 05:36 AM

Is there any particular reason you can't use a button. By default you can assign an image to a button.

alt text

Here's a little script I have made that will change the image (you will need to assign 'image' in the inspector).

 using UnityEngine;
 using System.Collections;
 using UnityEngine.UI;
 
 public class ChangeImage : MonoBehaviour {
     public Sprite image;
     Image imageComponent;
     // Use this for initialization
     void Start () {
         imageComponent = gameObject.GetComponent<Image> ();
     }
 
     public void Change()
     {
         imageComponent.sprite = image;
     }
 }

You will need to call 'Change()' on the button. So in the OnClick() section choose the object on the left and ChangeImage > Change() on the right.

alt text

Hope this helps :)


ui.jpg (110.3 kB)
channge-image.jpg (108.0 kB)
Comment
Add comment · Show 10 · 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 arjunh · Sep 19, 2016 at 08:08 AM 0
Share

@lawrence-parry actually i cant use button i have already done many things based on this image, can you provide a reference how a new canvas pops up when one image is clicked

avatar image lawrence-parry arjunh · Sep 19, 2016 at 09:45 PM 0
Share

I really don't see why you can't use a button. A button has the very same image component as a regular image.

avatar image arjunh · Sep 20, 2016 at 05:05 AM 0
Share

@lawrence-parry actually am using unity 3d , when i am adding a button it appear like empty am new to this. what i actually want is.... a button for settings, and when button is clicked the setting window should pop up and their should be a option to mute the volume, can you provide me a reference, i will click for your answer

avatar image lawrence-parry arjunh · Sep 21, 2016 at 08:37 AM 0
Share

Could you explain a little more about what it is you are after? You want to display a settings window that you have already created when a button is pressed is that right?

avatar image arjunh · Sep 21, 2016 at 08:43 AM 0
Share

@lawrence-parry yes thats right... actualy settings window is a gameobject in which i have added an image

avatar image lawrence-parry arjunh · Sep 21, 2016 at 09:23 AM 0
Share

You will probably want to have the settings window disabled by default; uncheck the checkbox at the top left of the inspector when you have your settings object selected. Then enable the object through script when the button is pressed.

  using UnityEngine;
  using System.Collections;
  
  public class ChangeImage : $$anonymous$$onoBehaviour {
     
  public GameObject settings;
    
  
      public void Change()
      {
          settings.SetActive(true);
      }
  }

You will need to set the settings object for the script in the inspector.

avatar image lawrence-parry lawrence-parry · Sep 21, 2016 at 09:25 AM 0
Share

If you want to hide the settings window again use:

 settings.SetActive(false);
avatar image arjunh · Sep 22, 2016 at 05:11 AM 0
Share

is it possible to pass the data from one scene to another

avatar image arjunh · Sep 22, 2016 at 05:12 AM 0
Share

@lawrence-parry i have a doubt... what i have to do is to make few buttons on the main scene... one setting button ,one shopping button, one mission button, one facebook button...when i click each button new window should come ....how can i do that can you provide me some reference...

one more doubt... if i make 4 separate scene for each buttons and load each scene when each corresponding buttons are clicked is it ok?

hope you will give a suggetion

avatar image lawrence-parry arjunh · Sep 22, 2016 at 11:14 AM 0
Share

I wouldn't recommend having separate scenes for when each button is pressed; the game will have to load the new scene when the button is pressed and then load the old one if you switch back again. I think your best bet is enabling and disabling gameobjects. So when one button is pressed you can disable a object containing those buttons (settings, shop, missions etc.) and then enable another object with whatever you now want to be displayed. For example if the settings button is pressed you will disable your object containing the buttons and then enable an object which has your settings menu in it.

P.S. for saving data between scenes create a class, here I'm using one I've called 'GlobalVariables'

 public static class GlobalVariables
 {
 public static string SavedBetweenScenes = "this string can be accessed from any scene"
 }

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

78 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 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

how can i change the color of line renderer 1 Answer

Make simple hit effect 1 Answer

can anyone tell what this script actually does 0 Answers

drag gameobject from ui scroll panel to 3d space 0 Answers

how to make a running player fly through the air at a particular distance from the ground 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