Hot answers tagged

161

Do not store those strings, store the (cryptographic) hash of them. A (cryptographic) hash function, like encryption, is a way to turn a string into "gibberish" (called hash), but unlike encryption, you cannot get the original string from this hash (unless you can brute-force it or the hash function is broken). Most (if not all) hash functions takes a ...


105

What you are trying to do is both futile and pointless. It is futile because there is no way to properly hide information which is on the user's machine. Anyone dedicated enough will find it. You can make it harder, but you can never prevent it. If you encrypt it, then you need to store the encryption key and algorithm somewhere. No matter how many layers ...


80

I can certainly see why you would think that it would be hard to simulate those, but there are enough constraints on bullets (all projectiles, really) to make them easier. They are generally simulated as a single point, instead of as something with volume. This makes collision detection significantly easier, as now I only need to do collisions against ...


56

It depends, but usually I use a third method. The problem with the methods that you used is that in the event that the object is included to begin with, it will not remove them from the tree, and they can still be created by instantiating too many calls, which could make things really confusing. public class SomeClass : MonoBehaviour { private static ...


53

Using GL Lines: I would recommend using the the GL API for drawing lines. The line thickness will always be 1px on screen and there is no option to change it. There will also be no shadows. The GL method calls are executed immediately so you need to make sure to call them after the camera has already rendered. Attaching the script to the camera and using ...


51

Go with the second approach, simply due to the fact that you can introduce new resource types or items at any time without having to rewrite or update code (data driven development). Edit: To elaborate a bit more on why this is in general good practice, even if you're 100% sure some value won't ever change. Let's take the console game example mentioned in ...


50

The jittering is happening because you're warping the player into the wall using Transform.Translate, and the physics step is saying, "Hey, we're in the wall. Let's solve this collision issue and push the player back out of the wall." To avoid this, when using a Rigidbody2D, it's advisable to use Rigidbody2D.MovePosition. This ensures you won't have ...


46

Animations in which the character translates away from the origin are said to contain "Root Motion" - because the root bone moves. This allows the animator to directly author subtle non-uniformities in the movement speed, in a "what you see is what you get" fashion. Say the character slows down slightly as their foot makes contact with ...


45

Probably one of the most efficient ways to implement bullets is using what is known as hitscan. It is rather simple in its implementation - when you fire, you check to see what the gun is aiming at (possibly using a ray to find the closest entity/object/mesh), and then you 'hit' it, doing damage. If you want to make it seem more like an actual, fast moving ...


45

If the object is instantiated correctly despite the Intantiate() line throwing an exception, then the error is coming from another instance of the script — you might accidentally have a second copy in your scene. One instance is configured correctly, and performing the Instantiate() as expected with no errors, so the object is created as desired. Another ...


41

If you're planning to instantiate many instances of the same prefab, you should definitely think about using object pooling. Calling Unity's Instantiate function is one of the most taxing method calls you could make. Object pooling is when you instantiate prefabs before they are used. They are deactivated immediately upon instantiation and reactivated only ...


36

What you have here is a classic O(n²) algorithm. The root cause of your problem has nothing to do with threading and everything to do with the fact that your algorithm has a high complexity. If you haven't come across "Big O" notation before, it basically means the number of operations required to work on n elements (this is the super-simplified explanation)...


36

Here's a quick summary: Create object Removes scene Global Keep across if not in scene? duplicates? access? Scene loads? Method 1 No No Yes Yes Method 2 Yes No Yes No PearsonArtPhoto No Yes Yes ...


32

Planning to grow: Hard-coded constants are fine for small projects but, eventually, as your software grows in size, you will wish you could change those settings without having to recompile everything. There are many times you will want to change settings while the game is running and you can't do that with hard-coded constants. CVars: Once your project ...


31

To simulate a time lag, use a circular buffer to store the last N frames' mouse positions. Store the current mouse position each frame. In your control calculations, use the oldest mouse position from the buffer instead of the current mouse position.


31

You could specify the namespace explicitly: System.Random random = new System.Random(seed); random.Next();


29

As a game developer, my main concern hiring a C# guy would be a lack of low-level knowledge. So, consider a project where your work entails low-level optimization like re-arranging the data layout of classes or rewriting code to take advantage of SIMD instructions. Take a C++ open-source game, optimize it, and post the framerate increase on your resume. If ...


29

I am a complete beginner in Unity, but this is how I do it at the moment, and it reduces the editor usage to minimum: In editor, I only have three objects: An empty GameObject called "main", a camera, and a light. And this is only because so far I only work with a single camera and a single light, so it was faster this way. Later I will probably remove them,...


29

There's a class named TextAssets which is used for text file reading. http://docs.unity3d.com/Manual/class-TextAsset.html Here you can find the supported file format. So if you want to read the text file, the script would be like this: class YourClassName : MonoBehaviour{ public TextAsset textFile; // drop your file here in inspector void ...


29

A rule of thumb is that you use different classes when objects require different code and instances of the same class when the objects only require different values. When the resources have different game mechanics which are unique to them, it might make sense to represent them with classes. For example, when you have Plutonium which has a half-life time ...


28

I would recommend checking out the explosion iforce2d page. It does a great job going over the various ways of handling explosions with the performance vs. accuracy tradeoffs. It goes over 3 methods which I will summarize here. So this is simply me summarizing information I found while researching and none of it is my own work. Also you want to apply ...


28

The best implementation of a generic Singleton pattern for Unity I know of is (of course) my own. It can do everything, and it does so neatly and efficiently: Create object Removes scene Global access? Keep across if not in scene? duplicates? Scene loads? Yes Yes ...


27

This effect is very easy to produce in Unity using a couple of Box Colliders, and some basic math. The effect will ressemble the following: This is a very simple model for this problem. First you need 3 gameobjects added to your scene. Each object will contain a BoxCollider2D and a RigidBody2D with gravity removed. The blue boxes just have a simple ...


27

Hash codes are never guaranteed to be unique. Also, you do not get a guarantee that adding hash-codes gets you an unique value which does not collide with a different combination of hash-codes. The usual solution to identify a combination of on/off flags is to use a bitfield. Assign manual integer values to your enum which are all powers of two: [Flags] //...


27

Defining >= for a Vector3 type makes no sense. What determines if one vector is greater than another? Their magnitude or their individual x, y, z components? A vector is a magnitude & a direction. So what determines what direction is greater? If you need to compare the magnitudes you can use sqrMagnitude. In this case Vector3 overrides == to ...


25

A common approach is to have a component-based approach where the base-class "Unit" just implements the most basic aspects all units have in common, while each unit then has a list of multiple component-objects which say what it can do and how it does it. For example, a tank might have the components Mobile, Destructible, Attacker, an immobile turret only ...


Only top voted, non community-wiki answers of a minimum length are eligible