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 pretender · Aug 23, 2010 at 06:24 PM · coroutineclassyield

problem with using classes and coroutines

i just figured that i can't use yield in a class that is derived from the object like this:

class CLabels extends Object{

var startPoint : Vector3; var endPoint : Vector3;

var labelRect : Rect;

var rPosx : int; var rPosy : int;

var rWidth : int; var rHeight : int;

var target : Transform;

var cam : MainCamera; var lineMaterial : Material;

function DrawLabel(currentTarget : Transform){

  Start(); 
  CalculateLinePositions(); 
  OnGUI(); 
  OnPostRender(); 
  MonitorRectState(); 

} //END OF DRAW FUNCTION

//OTHER FUNCTIONS HERE

}

basically what i was trying is to make a class that will draw label on top of selected object. it draws line from the object to the rectangle that holds information about the object. everything works fine, i should say worked fine, until i wanted to make the function that will slide the rectangle to the side when it is located on top of the object, so it doesnt obscure it. so what now? how to use coroutines?

also i am new in writing classes, i dont know if i am doing it the right way. i dont have a constructor, i dont know how to use it. also i am calling OnGUI and OnPostRender from within functions that i wrote. i dont know is that the way to do it...

thanks!

also i noticed that when i want to use image button inside the class like this:

var image : Texture2D ...

if(GUI.Button(Rect(200,200,40,40),image)){

//do something;

}

it doesnt work, if i do the same thing in the usual script that is attached to the camera i get the button image... go figure..i know i am doing something wrong but i dont know what exactly...

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
2

Answer by Eagle32 · Aug 23, 2010 at 09:25 PM

also i am calling OnGUI and OnPostRender from within functions that i wrote.

Don't.

it doesnt work, if i do the same thing in the usual script that is attached to the camera i get the button image... go figure..i know i am doing something wrong but i dont know what exactly...

That's not going to work, a class has to derive from MonoBehaviour if you want to be able to use OnGUI, Update, Start, Awake, etc

EDIT

I just realised you're writing javascript not C#. The class decleration isn't needed in javascript. Take that out and the script will automatically extend from MonoBehaviour.

OnGUI, Update, Start, Awake, etc all get called by Unity automatically at the appropriate times. OnGui is where all your drawing code should be.

What does MonitorRect state do? I don't know so I'll guess update is the best place for it.

var startPoint : Vector3; var endPoint : Vector3;

var labelRect : Rect;

var rPosx : int; var rPosy : int;

var rWidth : int; var rHeight : int;

var target : Transform;

var cam : MainCamera; var lineMaterial : Material;

function Update(){

  CalculateLinePositions(); 
  MonitorRectState(); 

}

//OTHER FUNCTIONS HERE

Comment
Add comment · 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 pretender · Aug 24, 2010 at 09:20 AM 0
Share

ok, i figured that i shouldnt do it that way...but how to do it then??

avatar image Eagle32 · Aug 24, 2010 at 10:51 PM 0
Share

I've update the answer a bit, but you need to provide more information about what you are trying to do with yield and coroutines for anyone to be able to help more.

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

C# yield not doing anything 2 Answers

How to use yield within a class function 2 Answers

Null Reference Exception after updating from 4.0 to 4.1.5 (coroutines) 0 Answers

Last item not being moved (yield problem) 0 Answers

Coroutoutine doesnt work properly. 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