Hot answers tagged

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] ...


4

As Phillipp said, HashCodes do not guarantee uniqueness. In fact they pretty much don't guarantee anything. What you seem to want to do is to generate a unique number from a unique string. How to do that generically is answered in this question: How can I generate a GUID for a string? If you just want a unique identifier which is allowed to differ even for ...


3

Your problem is that you're trying to compare floating-point numbers for equality. The matrix inversion and multiplication, however, will inevitable introduce slight rounding errors that will make the numbers in the two matrices not exactly equal. Still, let's compare your debug printouts side by side. I've deleted the M1 and TR rows, and left just the ...


2

It might be useful to note that while it is not guaranteed to be unique, your original approach is still going to work in practice with small amounts of traits, and a collision would not even have disastrous consequences if it happened. The chance that some combination of hashes will match the hash some other trait is n!/2^32 (for a 32-bit hash), which is ...


2

Most instances I've seen of graph rewriting for map generation solve the collisions problem (I.E overlapping rooms) by restricting the graph nodes to regular, modular components. For instance, this example, taken from Procedural generation of dungeons uses rooms that are laid out on regular intervals:


2

Identifiers in C# are case sensitive. You want iteminfo.text not iteminfo.Text You can verify in the docs that the UnityEngine.UI.Text.text property is all-lowercase.


1

float Timer = 2f; float TIMER = 2f; float StartVelocity = 10; float EndVelocity = 0; void Update() { float elapsed = (float)gameTime.elapsedSecondsOrWhatever; Timer -= elapsed; if (Timer < 0) Timer = 0; velocity.Y = MathHelper.Lerp(EndVelocity, StartVelocity, Timer/TIMER); }


1

You'd do this in the opposite order. Rather than: Create Modify Attach to GameObject (there's no way provided to do this) the order is: Create and attach to GameObject (one fused step) Modify Like so: GameObject go = new GameObject(); MeshRenderer newmeshrenderer = go.AddComponent<MeshRenderer>(); // Do stuff with newmeshrenderer, eg... ...


1

It should work like the example on the Scripting API for AddComponent http://docs.unity3d.com/ScriptReference/GameObject.AddComponent.html MeshRenderer mr = gameObject.AddComponent("MeshRenderer"); (...) //do stuff with mr


1

Check broad-phase collision detection. Example link That would reduce the collision detection cost. Then figure out WHAT causes your performance drop. Virtual method calls themselves are not that expensive - 1000 of them in a frame will definitely NOT cause a slideshow. Perhaps the message system is slow? The message creation copies data by value? etc etc. ...


1

Acually you want to load resource from your project views there are 2 ways to do this.(which I know if somebody know more then surely update this answer) Resource.Load Asset Bundles 1 . Resource Example void Start() { GameObject go = GameObject.CreatePrimitive(PrimitiveType.Plane); Renderer rend = go.GetComponent<Renderer>(); ...


1

I finally succeeded to get rid of this behaviour. (Thanks @Jon !) "Don't let the snake change its direction if it heads backward from its current heading. " It actually works :) Example with 'Up' Direction : int X = _snake._parts.Last().X; int Y = _snake._parts.Last().Y; if (newDirection == Direction.Haut) { Rectangle test = new Rectangle(X, Y - ...


1

I don't really understand your question to be honest but I think you're trying to figure out how to find the world matrix of a child node. In other words, you essentially have a scene graph with parent nodes and child nodes and you want to know how to calculate the world matrix of one of the children. Essentially it's a two step process. First you need to ...


1

The main problem here is that you don't have some sort of game loop. You record the keypress, but not the continious keydown (thus, if the letter 'A' is pressed for 10 seconds, only 1 event is triggered). Now this could be expected behaviour (only move one square one keypress at a time). With a gameloop you can have the object moving independant of the ...


1

The other approach I've seen is to use a generate & test (aka trial & error) approach. Basically, a rule is selected & if the result would be valid, it is applied. If the result is invalid (I.E. overlapping rooms) usually it is discarded & a new rule is attempted. Other times, it may be possible to modify the results. In a sense, both of ...



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