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
1
Question by GingerV1k1ng · Apr 17, 2013 at 12:47 PM · c#gui

Why does my slide out menu not work when i translate from JS to C#?

So I am practesing my translation and i decided to make a slide script in JS and it works like it should, so i started with the translation but I am having a problem in the sliding function itself it won't do it. My JS script:

 var MyBoxLeft = -200.0;
 
 var icon : Texture; var icon2 : Texture; var blankSkin : GUISkin;
 
 function OnGUI () { GUI.skin = blankSkin; var tBoxRect = new Rect(MyBoxLeft, 20.0, 220, 720); var tButtonRect = new Rect(MyBoxLeft, 160.0, 120, 30); var tBoxArt = new Rect(MyBoxLeft, 200.0, 120, 120);
 
 GUI.Box(tBoxRect, icon); GUI.Button(tButtonRect, "Click"); GUI.Box(tBoxArt, icon2); }
 
 function Update () {
 
 if (Input.GetKeyDown("space")) { AnimateBox(); }
 
 }
 
 function AnimateBox () {
 
 if (MyBoxLeft == -200.0) {
 
     while (MyBoxLeft < 20.0) {
     MyBoxLeft+=5.0;
     yield;
     }
 
 } else if (MyBoxLeft == 20.0) {
 
     while (MyBoxLeft > -200.0) {
     MyBoxLeft-=5.0;
     yield;
     }
 
 }
 
 }

and here is the C# script i have made:

 using UnityEngine;
 using System.Collections;
 
 public class GUI_Script : MonoBehaviour
 {
 
     float MyBoxLeft = -200f;
 
     public Texture icon;
     public Texture icon2;
     public GUISkin blankSkin;
 
     void OnGUI()
     {
         GUI.skin = blankSkin; 
         Rect tBoxRect = new Rect(MyBoxLeft, 20.0f, 220, 720);
         Rect tButtonRect = new Rect(MyBoxLeft, 160.0f, 120, 30);
         Rect tBoxArt = new Rect(MyBoxLeft, 200.0f, 120, 120);
 
         GUI.Box(tBoxRect, icon); GUI.Button(tButtonRect, "Click"); GUI.Box(tBoxArt, icon2);
     }
 
     void Update()
     {
 
         if (Input.GetKeyDown("space")) { AnimateBox(); }
 
     }
 
     void AnimateBox()
     {
 
         if (MyBoxLeft == -200.0f)
         {
 
             while (MyBoxLeft < 20.0f)
             {
                 MyBoxLeft += 5.0f;
                 yield return 0;
             }
 
         }
         else if (MyBoxLeft == 20.0f)
         {
 
             while (MyBoxLeft > -200.0f)
             {
                 MyBoxLeft -= 5.0f;
                 yield return 0;
             }
 
         }
 
     }
 }

I know that I need to make the void AnimateBox() to a IEnumerator for it to say it works, but it will not scroll.

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
Best Answer

Answer by whydoidoit · Apr 17, 2013 at 12:48 PM

You need to make AnimateBox an IEnumerator and call it with StartCoroutine(AnimateBox());

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 GingerV1k1ng · Apr 17, 2013 at 12:59 PM 0
Share

Thanks it works :D

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

12 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

Related Questions

Multiple Cars not working 1 Answer

GuiTexture Width Change 1 Answer

JS to C# Translation? 2 Answers

Is There A Way To Make Sprites Clickable? 1 Answer

Making my GUI Button Movable in Play mode 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