Hi I am working in Unity with c#. I want to make that the player can draw a box on the…
- User
Hi I am working in Unity with c#. I want to make that the player can draw a box on the screen and define storage areas inside a grid. So now my problem is that I am unsure about the datatype that I should use. Should I use a grid that only stores the storage id and a second list that stores all the data what belongs to that storage (e.g. can put milk, bread stone etc. in here) and the size of the storage so I dont have to search in the big world grid. I want to make it performant but also the data size important since I have to save this too.
- Assistant
- User
Wie schreibe ich einen constructor für ein struct
- Assistant
In C# verwendest du für die Erstellung eines Konstruktors in einem ein ähnliches Vorgehen wie bei Klassen, allerdings mit einigen speziellen Überlegungen bezüglich der Werttyp-Eigenschaften von .
- User
wie viel speicher braucht eine Zelle bestehend aus diesen daten typen? public byte id_area; public byte flags; public interactable item;
- Assistant
Die Größe des Speichers, den eine Zelle in C# benötigt, hängt von den Datentypen der Mitglieder der Zelle und möglicherweise von der Plattform (32-Bit vs. 64-Bit) sowie von Compiler-Optimierungen (wie Padding und Alignment) ab. Hier gebe ich eine allgemeine Aufschlüsselung basierend auf den von dir bereitgestellten Datentypen:
- User
how do I calculate a x,y coordinate into a single array? with gridszie x = 100 and y = 100
- Assistant
To map a two-dimensional coordinate (x, y) into a single-dimensional array when dealing with a grid, you can use a formula to convert these coordinates based on the grid size. Assuming your grid size is (100 \times 100), meaning you have 100 columns (width) and 100 rows (height), the formula that translates the two-dimensional coordinate into a single-dimensional index is:
[ \text{index} = y \times \text{width} + x ]
Explanation:
- width: It is the number of columns in the grid, in your case, 100.
- x: It is the horizontal position (from 0 to 99 if there are 100 columns).
- y: It is the vertical position (from 0 to 99 if there are 100 rows).