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 /
avatar image
0
Question by Nabil_fx · Apr 21, 2014 at 06:36 PM · 3dplayerprefsmaya

Button Help

I have a script with GUIBox button, writted in the script, I need to put the script to work with a UNity 3D plane.obj as a button, I need help to implement that, i dont want the GUIBox button from the script.

If yes i put the script here. ok.

Comment
Add comment · Show 1
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 robertbu · Apr 21, 2014 at 06:37 PM 0
Share

Yes please add your script. For a plane object, you can put code in On$$anonymous$$ouseDown() to catch the click event...works with touch as well.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Nabil_fx · Apr 21, 2014 at 07:06 PM

Ok here is a picture atach, showing the GUIbox button, and the Plane that i need to work as a button, and the script is here. I need 1 Plane button for each Guibox button. alt text

 using UnityEngine;
 using System.Collections;
 
 public class PostSampleFull : MonoBehaviour {
 
     private Demo demo;
 
     private string text = "Message";    
     private string url = "https://www.assetstore.unity3d.com/#/content/9277";    
 
     private int unityVersion = 0;
     private TouchScreenKeyboard keyboard = null;
 
     private Texture2D texCaptureScreen = null;
 
     private bool activityPopoverEnable = true;
 
 
     // Use this for initialization
     void Start () {
         demo = GameObject.Find("Main Camera").GetComponent<Demo>();
 
         char[] version = Application.unityVersion.ToCharArray();
         unityVersion = (((version[0]-'0') * 100) + ((version[2]-'0') * 10) + (version[4]-'0'));
     }
     
     private IEnumerator CaptureScreen() {
         yield return new WaitForEndOfFrame();
         texCaptureScreen = ScreenCapture.Capture();
     }
 
     void OnGUI () {
         // Scaling
         float scale = (Screen.width > Screen.height) ? (Screen.width/960.0f) : (Screen.height/960.0f);
         Vector2 guiCanvasSize = new Vector2(Screen.width/scale, Screen.height/scale);
         GUIUtility.ScaleAroundPivot(new Vector2(scale, scale), Vector2.zero);
         
         // Buttons
         const int buttonCount = 4;
         float buttonWidth = guiCanvasSize.x/(buttonCount+1);
         float buttonHeight = guiCanvasSize.y/4;
         float buttonMargine = buttonWidth/(buttonCount+1);
         Rect buttonRect = new Rect(0, guiCanvasSize.y-buttonHeight, buttonWidth, buttonHeight);
 
         // Tweet
         bool doTweet = false;
         buttonRect.x = buttonMargine;
         if (iOS_PostToServices.CanTweet()) {
             doTweet = true;
         } else {
             uint state = iOS_PostToServices.GetTwitterState();
             if (state == iOS_PostToServices.StateNotAvailable_Platform) {
                 GUI.Box(buttonRect, "Tweet\n(Unavailable)\n\n-> iOS Only");
             } else if (state == iOS_PostToServices.StateNotAvailable_iOSVersion) {
                 GUI.Box(buttonRect, "Tweet\n(Unavailable)\n\n-> Lower iOS Version");
             } else if (state == iOS_PostToServices.StateNotAvailable_Account) {
 //                GUI.Box(buttonRect, "Tweet\n(Unavailable)\n\n-> Setup\nTwitter Account");
                 doTweet = true;
             } else {
                 GUI.Box(buttonRect, "Tweet\n(Unavailable)");
             }
         }
         if (doTweet && GUI.Button(buttonRect, "Tweet")) {
             #if UNITY_IPHONE
                 if (Application.platform == RuntimePlatform.IPhonePlayer) {
                     // Tweet (iOS 5.0 or later)
                     if (iOS_PostToServices.Tweet (text, url, texCaptureScreen, this.name, "OnFinishedPostToService")) {
                         demo.Pause(true);
                     }
                 }
             #endif
         }
 
         // Facebook
         bool doPostToFacebook = false;
         buttonRect.x += (buttonWidth + buttonMargine);
         if (iOS_PostToServices.CanPostToFacebook()) {
             doPostToFacebook = true;
         } else {
             uint state = iOS_PostToServices.GetFacebookState();
             if (state == iOS_PostToServices.StateNotAvailable_Platform) {
                 GUI.Box(buttonRect, "Post to \nFacebook\n(Unavailable)\n\n-> iOS Only");
             } else if (state == iOS_PostToServices.StateNotAvailable_iOSVersion) {
                 GUI.Box(buttonRect, "Post to \nFacebook\n(Unavailable)\n\n-> Lower iOS Version");
             } else if (state == iOS_PostToServices.StateNotAvailable_Account) {
 //                GUI.Box(buttonRect, "Post to \nFacebook\n(Unavailable)\n\n-> Setup\nFacebook Account");
                 doPostToFacebook = true;
             } else {
                 GUI.Box(buttonRect, "Post to \nFacebook\n(Unavailable)");
             }
         }
         if (doPostToFacebook && GUI.Button(buttonRect, "Post to\nFacebook")) {
             #if UNITY_IPHONE
                 if (Application.platform == RuntimePlatform.IPhonePlayer) {
                     // Facebook (iOS 6.0 or later)
                     if (iOS_PostToServices.PostToFacebook (text, url, texCaptureScreen, this.name, "OnFinishedPostToService")) {
                         demo.Pause(true);
                     }
                 }
             #endif
         }
 
         // Mail
         buttonRect.x += (buttonWidth + buttonMargine);
         if (iOS_PostToServices.CanMail() == false) {
             uint state = iOS_PostToServices.GetMailState();
             if (state == iOS_PostToServices.StateNotAvailable_Platform) {
                 GUI.Box(buttonRect, "Mail\n(Unavailable)\n\n-> iOS Only");
             } else if (state == iOS_PostToServices.StateNotAvailable_iOSVersion) {
                 GUI.Box(buttonRect, "Mail\n(Unavailable)\n\n-> Lower iOS Version");
             } else if (state == iOS_PostToServices.StateNotAvailable_Account) {
                 GUI.Box(buttonRect, "Mail\n(Unavailable)\n\n-> Setup\nMail Account");
             } else {
                 GUI.Box(buttonRect, "Mail\n(Unavailable)");
             }
         } else if (GUI.Button(buttonRect, "Mail")) {
             #if UNITY_IPHONE
                 if (Application.platform == RuntimePlatform.IPhonePlayer) {
                     // Mail (iOS 3.0 or later)
                     iOS_PostToServices.MailInfo mailInfo;
                     mailInfo.subject = "Subject";
                     mailInfo.toList = new string[1] { "to@mail.com" };
 #if true
                     mailInfo.ccList = null;
                     mailInfo.bccList = null;
 #else
                     mailInfo.ccList = new string[2] { "cc@mail.com", "cc2@mail.com" };
                     mailInfo.bccList = new string[3] { "bcc@mail.com", "bcc2@mail.com", "bcc3@mail.com" };
 #endif
                     if (iOS_PostToServices.SendMail (ref mailInfo, text, url, texCaptureScreen, this.name, "OnFinishedPostToService")) {
                         demo.Pause(true);
                     }
                 }
             #endif
         }
 
         // Activity
         buttonRect.x += (buttonWidth + buttonMargine);
         if (iOS_PostToServices.CanPostToActivity() == false) {
             uint state = iOS_PostToServices.GetActivityState();
             if (state == iOS_PostToServices.StateNotAvailable_Platform) {
                 GUI.Box(buttonRect, "Activity\n(Unavailable)\n\n-> iOS Only");
             } else if (state == iOS_PostToServices.StateNotAvailable_iOSVersion) {
                 GUI.Box(buttonRect, "Activity\n(Unavailable)\n\n-> Lower iOS Version");
             } else {
                 GUI.Box(buttonRect, "Activity\n(Unavailable)");
             }
         } else if (GUI.Button(buttonRect, "Activity")) {
             #if UNITY_IPHONE
                 if (Application.platform == RuntimePlatform.IPhonePlayer) {
                     // Activity (iOS 6.0 or later)
                     iOS_PostToServices.SetActivityPopoverEnable_for_iPad (activityPopoverEnable);
                     iOS_PostToServices.SetActivityPopoverTargetRect_for_iPad (buttonRect.x*scale, buttonRect.y*scale, buttonRect.width*scale, buttonRect.height*scale);
                     uint disableFlags = 0
 //                                | iOS_PostToServices.ActivityTypePostToFacebook
 //                                | iOS_PostToServices.ActivityTypePostToTwitter
 //                                | iOS_PostToServices.ActivityTypePostToWeibo
 //                                | iOS_PostToServices.ActivityTypeMessage
 //                                | iOS_PostToServices.ActivityTypeMail
 //                                | iOS_PostToServices.ActivityTypePrint
 //                                | iOS_PostToServices.ActivityTypeCopyToPasteboard
 //                                | iOS_PostToServices.ActivityTypeAssignToContact
 //                                | iOS_PostToServices.ActivityTypeSaveToCameraRoll
                                 // iOS 7 over
 //                                | iOS_PostToServices.ActivityTypeAddToReadingList
 //                                | iOS_PostToServices.ActivityTypePostToFlickr
 //                                | iOS_PostToServices.ActivityTypePostToVimeo
 //                                | iOS_PostToServices.ActivityTypePostToTencentWeibo
 //                                | iOS_PostToServices.ActivityTypeAirDrop
                     ;
                     iOS_PostToServices.SetActivityDisableFlags (disableFlags);
                     if (iOS_PostToServices.PostToActivity (text, url, texCaptureScreen, this.name, "OnFinishedPostToService")) {
                         demo.Pause(true);
                     }
                 }
             #endif
         }
 //        buttonRect.y -= 40/scale;
 //        buttonRect.height = 40/scale;
 //        activityPopoverEnable = GUI.Toggle(buttonRect, activityPopoverEnable, "Enable\nPopover");
 
         // Text, URL and Image
         GUI.Box(new Rect(0,0, guiCanvasSize.x*0.25f, guiCanvasSize.y*0.6f), "");
         buttonRect.x = buttonRect.y = 0;
         buttonRect.width = guiCanvasSize.x/4;
         buttonRect.height = guiCanvasSize.y/8;
         if (((unityVersion >= 410) && (unityVersion < 420)) && (Application.platform == RuntimePlatform.IPhonePlayer)) {
             if (GUI.Button(buttonRect, text)) {
                 keyboard = TouchScreenKeyboard.Open(text, TouchScreenKeyboardType.NamePhonePad, /*autocorrection=*/true, /*multiline=*/false);
             }
             if (keyboard != null) {
                 text = keyboard.text;
             }
             buttonRect.y += buttonRect.height;
             if (GUI.Button(buttonRect, url)) {
                 keyboard = TouchScreenKeyboard.Open(url, TouchScreenKeyboardType.NamePhonePad, /*autocorrection=*/true, /*multiline=*/false);
             }
             if (keyboard != null) {
                 url = keyboard.text;
             }
         } else {
             text = GUI.TextArea(buttonRect, text);
             buttonRect.y += buttonRect.height;
             url = GUI.TextArea(buttonRect, url);
         }
         buttonRect.y += buttonRect.height;
         buttonRect.height = guiCanvasSize.y/10;
         if (GUI.Button(buttonRect, "Capture\nScreen")) {
             StartCoroutine("CaptureScreen");
         }
         buttonRect.y += buttonRect.height;
         if (texCaptureScreen) {
             GUI.DrawTexture(new Rect(buttonRect.x,buttonRect.y, guiCanvasSize.x/4,guiCanvasSize.y/4), texCaptureScreen);
         }
     }
 
     #if UNITY_IPHONE
     private void OnFinishedPostToService (string message) {
         demo.Pause(false);
     }
     #endif
 }
 



scriptbutton.jpg (101.2 kB)
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

20 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

Related Questions

Script Help 3D touch animation 1 Answer

Unity isn't recognizing Maya 2010 .mb file? 5 Answers

A node in a childnode? 1 Answer

change to glow texture on mouse click 0 Answers

Structs in C# Question 3 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