• 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 /
avatar image
Question by aronatvw · Feb 01, 2014 at 05:08 AM · uiguitextureuser interfaceonmousedown

Please help with player selection screen

Hey fellas I have a picture that shows whats going on but also let me explain. I am making a player selection screen where you will select from multiple characters. I all ready have a plan for the bulk of the code I am stuck right in the beginning.

Basically I made four guitextrues as of right now and want to detect when they are pressed from a script attached to a plane. I don't want to do individual scripts for each guittexture and getcomponent and crap obviously. Am I doing this the hard way, please let me know and thank you in advance!alt text

capture.jpg (97.2 kB)
Comment

People who like this

0 Show 0
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

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by aronatvw · Feb 01, 2014 at 06:00 PM

I did not want to send message through all my code and honestly was not really understanding that method so I just wrote this code which works. All I have to do is change the public string to match it's relative method in the main script! It may be a bit barbaric maybe, but it works. Also I know getcomponent and invoke may be utilize a good amount of memory but its a very simple scene.

 using UnityEngine;
 using System.Collections;
 
 public class GUIClick : MonoBehaviour {
 
     private PlayerSelectionScreen playselecscreen;
 
     public GameObject bg;
     public string whattoinvoke;
 
 
     void OnMouseDown(){
 
         playselecscreen.Invoke(whattoinvoke, 0.0F);
 
 
     }
 
     // Use this for initialization
     void Start () {
     
         bg = GameObject.Find("PlayerSelectBG");
         playselecscreen = bg.GetComponent<PlayerSelectionScreen>();
 
     }
     
     // Update is called once per frame
     void Update () {
     
     }
 }
 
Comment

People who like this

0 Show 0 · 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

Answer by HuskyPanda213 · Feb 01, 2014 at 05:36 AM

Why do you use a GUI texture? Plus, I think you would have to make each texture have a script. The thing I would do is have a script called: GUISendMessage.cs, and have the code that follows.(for some reason it posted this when incomplete, but now it is complete)

 using UnityEngine; using System.Collections;
 
 public class GUISendMessage : MonoBehaviour {
 
 public string SendMessageName = "SendMessageFunctionName";//This is the function called in the Main/Manager Class.
 public GameObject SendMessageTo;//Place the Master Object in here
 
 void OnMouseDown(){
 SendMessageTo.SendMessage(SendMessageName);//If this gives an error use this SendMessageTo.SendMessage(SendMessageName,SendMessageOptions.DontRequireReceiver);This may is just for safety.
 }
 
 }

Then in the Main/Manager Class make a void called

 void TheMessageThatWasSentFromTheTexture(){//Don't really call it that, call it what the name of the string SendMessageName was.
 //Call stuff in here.
 }

If you do not understand the premise of SendMessage I will try to explain. SendMessage calls a function by what it is named. The input string, in the case the SendMessageName variable this will make a function with the name given in send message call. The SendMessageTo.SendMessage(), part makes it that it is sent to the gameobject with the Management script that has the functions that need to be called inside. If needing further help:

http://docs.unity3d.com/Documentation/ScriptReference/GameObject.SendMessage.html

Comment

People who like this

0 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 aronatvw · Feb 01, 2014 at 03:40 PM 0
Share

No I can figure that out, I was just hoping I could have detected the button clicked from the main script using public GUITexture.

avatar image aronatvw · Feb 01, 2014 at 03:41 PM 0
Share

So what do you recommend using as opposed to guitexture?

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

19 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

Related Questions

How to draw GUI texture under UI elements? 0 Answers

Unity 4.5.1 OnMouseDown() does not work on GUITexture 0 Answers

Highlight images in buttons children 0 Answers

How to store colors for future use 2 Answers

Scroll Rect Min/Max Size 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