• 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 Chris Ellingsworth · Dec 15, 2010 at 09:19 PM · coroutinereferenceparameters

Passing a rectangle as a parameter seems to have no effect on original using StartCoRoutine

Hi,

I'm trying to use a function where I pass a Rect as a parameter and modify the properties of that Rect, but it seems to have no effect when using StartCoRoutine. I can pass in the rectangle, but the "configureRectGroup" properties does not change. Is this expected behavior? Thanks!

Here's the relevant source:

public class MainMenu : MonoBehaviour {

public GUISkin mainMenuSkin; public GUISkin configureSkin;

// . Configure vars private Rect configureRectGroup = new Rect (0, 0, 240, 0); private Rect configureRect = new Rect (0, 0, 197, 336); // .

void Start () {

 StartCoroutine(ScaleIn(configureRectGroup, 0.333f, 0, configureRect.height));

}

private IEnumerator ScaleIn(Rect rec, float seconds, float fromHeight, float toHeight) { float t = 0.0f;

 while (t < 1.0f)
 {
     t += Time.deltaTime * (1.0f/seconds);

     rec.height = Mathf.Lerp(fromHeight, toHeight, Easing.Ease(t, Easing.EaseType.In));

     rec.y = Screen.height / 2 - (rec.height / 2);

     yield return true;
 }

}

}

Comment
Add comment · Show 2
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 Statement · Dec 16, 2010 at 12:03 AM 0
Share

Is yielding "true" doing anything special? (I honestly don't know) If not, the preferred way is to yield null (waiting for one frame). Yielding values cause boxing and unnecessary overhead. But please fill me in if "true" is used for anything. :)

avatar image Chris Ellingsworth · Dec 16, 2010 at 01:37 AM 0
Share

No, "true" is not doing anything. I'll change it to null, thanks for the tip!

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Peter G · Dec 15, 2010 at 09:23 PM

You would need to pass it by reference (ref and out keywords) since it is a value type, a struct, but:

But in my own experiences Unity does not allow you to pass parameters by reference in iterators like that (using while() then yield return something).

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 Chris Ellingsworth · Dec 15, 2010 at 09:29 PM 0
Share

Ahh, it's a struct. Yeah, I tried ref and out, which the compiler threw an error. Thanks Peter!

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

No one has followed this question yet.

Related Questions

Static and Coroutines help 2 Answers

How to pass "ref parameter" in iterator method? 1 Answer

How to shortcut a lambda expression through a function? 1 Answer

How can I pass a ref (AudioClip) into a coroutine? 2 Answers

How to stop coroutine with parameters? 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