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 MousePods · Aug 04, 2012 at 03:13 PM · c#arraysvector2struct

C# Point structure

Is there a way to store xy cooridnates in a point structure instead of a Vector2 (I dont want to have to convert the floats to int every time I use them)

I tried System.Collections.Generic;, but this still does not give the Point structure for C#. Is there another collections I need to use?

Thanks!

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

Answer by agamedesigner · Aug 04, 2012 at 03:50 PM

 struct Point
 {
     public int x, y;
 }

then use it like:

 Point myPoint;

 myPoint.x = 5;
 myPoint.y = 3;

you can also use it with a constructor:

 struct Point
 {
     public int x, y;

     public Point(int px, int py)
     {
         x = px;
         y = py;
     }
 }

in which case you could do this:

 Point myPoint = new Point(5, 7);
Comment
Add comment · Show 4 · 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 MousePods · Aug 04, 2012 at 04:11 PM 0
Share

Thanks! That really helped a lot!! =]!

If you read this, and have a second, I would like to know what exactly is going on. I have not really run into this type of set-up yet in my basic code skills.

Thanks again!!!

avatar image agamedesigner · Aug 04, 2012 at 05:01 PM 1
Share

Hi, a lot can be said about them so I've provided some links for you. Basically they are very similar to classes, but should generally be used for lightweight things only (unless you want to kill performance). They are a value type like int or char, as opposed to a reference type, which a class is.

$$anonymous$$ore on value vs reference types:

http://msdn.microsoft.com/en-us/library/t63sy5hs(v=vs.80).aspx

http://www.c-sharpcorner.com/uploadfile/e7ad16/reference-type-and-value-type-in-C-Sharp/

Here are the links on structs, in order:

http://msdn.microsoft.com/en-us/library/ah19swz4(v=vs.71).aspx

http://www.csharp-station.com/Tutorial/CSharp/lesson12

http://www.dotnetperls.com/struct

http://stackoverflow.com/questions/7484735/c-struct-vs-class-faster

http://stackoverflow.com/questions/521298/when-to-use-struct-in-c

Hope this helps!

avatar image MousePods · Aug 04, 2012 at 06:06 PM 0
Share

Thanks you!

avatar image jhina · Sep 27, 2015 at 09:18 PM 1
Share

@agamedesigner: You should implement IEquatable, GetHashCode and all that crap if you're going to implement your own Point class. Otherwise, Unity's old implementation of the .NET framework will create garbage in weird places. See: http://stackoverflow.com/questions/1307493/is-there-a-complete-iequatable-implementation-reference https://andrewfray.wordpress.com/2013/02/04/reducing-memory-usage-in-unity-c-and-netmono/

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

9 People are following this question.

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

Distribute terrain in zones 3 Answers

how do I move array objects to world coordinates? 1 Answer

Simple C# Vector2D Moving Question 1 Answer

Neural Network type conversion problem 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