Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
This question was closed Feb 03, 2013 at 03:59 PM by Fattie for the following reason:

Problem is not reproducible or outdated

avatar image
0
Question by Joseph118 · Feb 02, 2013 at 04:51 PM · c#button

I have created a button with photoshop and i need to use it in my menu

I have created a button with photoshop and i am trying to use it instead of my buttons I created.

Till now I have a script with C# that is attached to the main camera. The script basically makes the main menu for me but i would like to change the buttons generated with an image I designed.

This is what I have till now:

using UnityEngine; using System.Collections;

public class myMenu : MonoBehaviour {

 private delegate void MenuDelegate();
 private MenuDelegate menuFunction;
 
 private float screenHeight;
 private float screenWidth;
 private float buttonHeight;
 private float buttonWidth;
 
 // Use this for initialization
 void Start () {
     screenHeight = Screen.height;
     screenWidth = Screen.width;
     
     buttonHeight = screenHeight * 0.3f;
     buttonWidth = screenWidth * 0.4f;
     
     menuFunction = anyKey;
 }
 
 void OnGUI()
 {
     menuFunction();
 }
 
 void anyKey()
 {
     if(Input.anyKey)
     {
         menuFunction = mainMenu;
     }
     
     GUI.skin.label.alignment = TextAnchor.MiddleCenter;
     GUI.Label(new Rect(screenWidth * 0.45f, screenHeight * 0.45f, screenWidth * 0.1f, screenHeight * 0.1f), "Press any key to continue");
 }
 
 void mainMenu()
 {
     // Main Menu
     // Start Game
     // How to Play
     // Settings
     // Quit
             
     
     GUI.Box(new Rect((screenWidth - buttonWidth) * 0.6f, screenHeight * 0.05f, buttonWidth * 0.7f, buttonHeight * 2.5f), "Main Menu");
     
     if (GUI.Button (new Rect((screenWidth - buttonWidth) * 0.7f, screenHeight * 0.15f, buttonWidth * 0.4f, buttonHeight * 0.4f), "Start Game"))
     {
         Application.LoadLevel ("Level1");
     }
     
     if (GUI.Button (new Rect((screenWidth - buttonWidth) * 0.7f, screenHeight * 0.3f, buttonWidth * 0.4f, buttonHeight * 0.4f), "How to Play"))
     {
         
     }
     
     if (GUI.Button (new Rect((screenWidth - buttonWidth) * 0.7f, screenHeight * 0.45f, buttonWidth * 0.4f, buttonHeight * 0.4f), "Settings"))
     {
         
     }
     
     if (GUI.Button (new Rect((screenWidth - buttonWidth) * 0.7f, screenHeight * 0.6f, buttonWidth * 0.4f, buttonHeight * 0.4f), "Quit Game"))
     {
         Application.Quit();
     }
 }
 

}

My goal at the moment is to find a way how to make the script load the image and once clicked it does something like application.quit.

i have never coded in C# before, just Java and .Net, but i can understand C# since they are similar.

and what if i just simply drag and drop it in front of the main camera, making the camera facing 1 position during the main menu. Will i achieve the same results? what happens if the game gets maximized? will the GUI scatter? Sorry but i am still new to unity

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

2 Replies

  • Sort: 
avatar image
0
Best Answer

Answer by Joseph118 · Feb 03, 2013 at 03:58 PM

after some research i have found that i need to call the image from my materials using the following code

private Texture btnStart;

btnStart = (Texture)Resources.Load("btnStart");

if (GUI.Button (new Rect((screenWidth - buttonWidth) 0.7f, screenHeight 0.15f, buttonWidth 0.4f, buttonHeight 0.4f), btnStart))

Thank you for your attempts

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
avatar image
0

Answer by DryTear · Feb 02, 2013 at 05:51 PM

add

public GUISkin mySkin;

after the OnGui function has to be

void OnGui(){

  GUI.skin = mySkin;
  menuFunction();

}

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 Joseph118 · Feb 02, 2013 at 07:49 PM 0
Share

it gives me a compile error, please tell me more about GUI.skin

Follow this Question

Answers Answers and Comments

11 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

Related Questions

Multiple Cars not working 1 Answer

Selecting and deselecting not working 0 Answers

Distribute terrain in zones 3 Answers

C# Why Won't My GUI Layout Button Appear? 1 Answer

Finding the player that walked into a ray? 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