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 igotthis · Feb 24, 2014 at 09:19 AM · c#guiobjectclasssubclassing

Trying to change a subclasses' variable

Am I accessing the a classes' variables the wrong way? I'm trying to flip the values of a RECT and rRECT inside _item.cs's ITEM subclass from the "rotate()" function inside the guiBOX. Here's all my code on pastbine http://pastebin.com/99Lk71wf <- _item.cs http://pastebin.com/ABkeZJUP <- guiBOX.cs

and this is the specific code that i'm concerned about.

subclass of _item

 public class ITEM
     {
         
         public Texture IMAGE;
         public Rect RECT;
         public Rect rRECT;
         public Dictionary<string, string> itemStats;
         public int width;
         public int height;
         public List<Vector2> brecs;
         public ITEM(Texture I, Rect S, Dictionary<string, string> istats, int w, int h )
         {
             brecs = new List<Vector2>();
             height = h; width = w;
             itemStats =  istats; // list of the "key" and the "value" of each item, every item has a NAME and TYPE, based on TYPE it has
             //certain attributes so cost, description, etc.
             IMAGE = I;
             RECT = S;    
             rRECT = new Rect(S.x, S.y, S.width, S.height);
         }
         public void rotate(Rect R, Rect Z)
         {
 
             RECT = new Rect (R);
             rRECT = new Rect (Z);
         }
     }

rotate func from guiBOX

 public void rotate()
     {
         Rect R = new Rect (backpack [current].RECT);
         Rect Z =  new Rect (backpack [current].rRECT);
         R = new Rect (R.x, R.y, R.width, R.height);
         Z = new Rect (Z.x, Z.y, Z.width, Z.height);
         backpack [current].rotate (R, Z);
 
     }
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
0

Answer by RudyTheDev · Feb 24, 2014 at 11:29 AM

For one, your code doesn't actually "rotate" R and Z. You assign R from RECT, then remake R from R, then tell item to set RECT as R. So nothing changes. At the least, you should flip them around if that's what you are doing -- backpack [current].rotate (Z, R);.

As for the entire function, you can just do:

 public void rotate()
 {
     backpack[current].rotate(backpack[current].rRECT, backpack[current].RECT);
 }

Rect is a struct type, so it will copy its values not the reference, you don't need to worry about messing up references/instances. In other words, you don't need to new Rect() unless you are changing something.

But as far as I understand, you just want to swap/flip RECT with rRECT. You can just do this in ITEM:

 public void rotate() // or rename it SwapRects() or something more suitable
 { 
     Rect temp = RECT;
     RECT = rRECT;
     rRECT = temp;
 }

then your guiBOX code is

 public void rotate()
 {
     backpack[current].rotate();
 }
Comment
Add comment · Show 5 · 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 igotthis · Feb 24, 2014 at 04:39 PM 0
Share

It's. Just the. First step of rotate, I plan to change the texture next to a pre rotated one, but I need to swap the width with the height, which is not working for some reason.

avatar image RudyTheDev · Feb 24, 2014 at 04:53 PM 0
Share

I see you working with RECT and rRECT and your question says you are trying to flip their values. But you mention width/height, so which variables exactly are your width/height besides public int width, height? Can be you a little more specific about which part is supposed to do what you want but is not working?

avatar image igotthis · Feb 24, 2014 at 05:35 PM 0
Share

Rect = current frame's Rect for Textures in draw gui, rRect = last previously "snapped" Rect frame where you set it in the gui. All I'm trying to do is do is swap a rect's width with its height. and it seems to simply not work -_-

avatar image RudyTheDev · Feb 24, 2014 at 06:02 PM 0
Share

Can't you just do RECT = new Rect(RECT.x, RECT.y, RECT.height, RECT.width);?

avatar image igotthis · Feb 24, 2014 at 06:23 PM 0
Share

Oh.. wow thanks for the help but it turns out I was just retarded lol. Basically I was using the "current" variable when it was set to -1... weird that it wasn't throwing errors.

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

c# - void method from external class. 2 Answers

Instantiating objects from a class? (C#) 1 Answer

Distribute terrain in zones 3 Answers

Need idea for separate a surface of an 3D object 1 Answer

How do I use EditorGUIUtility.ShowObjectPicker()? C# 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