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 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.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

How to stop coroutine with parameters? 3 Answers

How do I assign a Gameobject's reference to a field variable as a parameter in a function? 1 Answer

How to make the Colour parameter in coroutine work with any anything with a colour variable. 2 Answers

How to use a float value from coroutine 1 and use in coroutine 2? 1 Answer

Object reference not set to an instance of an object 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