Tag Info

New answers tagged

0

Some clarifications. Only memory allocated by scripts is managed and can be garbage collected. So if you destroy a GameObject the attached script can be eventually collected, but the life time of resources allocated from the C++ side of the engine is managed in a different way. You can force a garbage collection explicitely call GC.Collect. If you don't ...


1

Destroy(); is an explicit command to remove the object from the game scene immediately* or after a set time increment. As soon as you call it - the item is destroyed in context of the scene. Garbage collection will take it as soon as there are no more when it is ready assuming there are no more hard references to that item. However, this is not ...


1

It is possible to achieve this using an HTTP server since the application won't require frequent messaging. However, the problem with the HTTP is that it cannot send messages to the client unless it requests something. Therefore, you need to send regular requests to receive state updates (such as 'is it my turn', 'piece positions changed?' etc.). Also, you ...


2

My output is always 00:00:01. Look at how you initialize your values, though: timer will default to zero t will initialize from timer, and is therefore also zero add will default to one second So we have zero, zero, and one. In each frame, you create a new TimeSpan value by adding t and add. It's important to note that calling Add does not modify ...


2

C++ should be very efficient, but it also would make me have to worry about low-level details like manual memory management, and compiling for different platforms. Modern C++ highly discourages manual memory management. You should instead use smart pointers like unique_ptr and allocation functions like make_unique and never manually allocate or ...


1

About c++: You dont really need to worry about memory management. Ofc you handle memory yourself, but its not as hard as in C. In C++ you just allocate your memory by creating a Object (new xyz();) and free this memory by deleting it (delete var;). No more manual malloc() and stuff) About Java: Java supports Call-by-value with primitives and ...


2

You can't put or execute statements during the class declaration. Why is projectile public? If you are assigning the variable from the editor, delete the third line and assign it. Otherwise, make it public and assign it manually from the Awake method. public class Player : MonoBehaviour { private Projectile pro; private void Awake() { ...


0

Just to update this question, I spent the last day doing some extensive searching, and I've found that using UniLua (made for use with unity, pure C# implementation) is the best and most effective option for getting Lua on Xbox. I stripped it down, took out all the Unity material, and it works great. I also added some functionality found in LuaInterface by ...


0

How are you retrieving the value of enemy? It is assigned at compile time, or retrieved at runtime? My advice would be to declare it as a GameObject, assign its value at runtime and then access its Transform value.


0

Here's my pseudo-code: When the player updates, get the position he wants to go. If it doesn't change, do nothing. Get the nearest blocks for that position, store them in an array or something. Go through that list / array, check for collisions If it collides, tweak the player's position until it doesn't collide with the block. For example, the player ...


1

Instead of checking a single block for collision, you could keep a list of blocks and then iterate through the list and perform collision responses for each block in the list. Like this: public void checkYCollisions(block[] platforms) { if (position.Y >= 700) grounded = true; else grounded = false; float Xradius = Width / 2; ...


1

You want a git post-commit or post-push hook to invoke your build chain automatically every-time those things happen. http://git-scm.com/book/en/Customizing-Git-Git-Hooks (Or you could use Jenkins? Same thing, but more complex. Though you might like those features.) Simply google "automated clickonce" to see that click once is not intended to be ...


3

Game assets like sounds are usually best managed if preloaded in advance. You don't want the user to experience a delay in the sound effects every time a sound has to be loaded. You should implement a ResourceCache helper that manages game resources for you. Then things like sounds could be preloaded at each level start and unloaded when the level ends. ...


0

You likely want to start with something simpler than creating a game if you get stuck at for loops. Here's the basic idea for creating a grid, you pretty much have everything you need. for (int x = 0; x < 8; x++) { for (int z = 0; z < 8; z++) { Instantiate(SquareObject, new Vector3(x,0,z), Quaternion.identity); } } This is a nested ...


0

What you are looking for is the Object Pool pattern which provides reusability and efficient memory usage. At the initialization level of the application, you simply create the instance and give it to the object pool. When you need to use it, pop it from the pool and send it back to the pool after you finish. In this way, you don't have to instantiate a new ...


1

I posted recently a response to a similar question http://stackoverflow.com/questions/24231389/struct-or-class-for-matrix-4x4-object Basically valuetypes are the way to go for storing matrices, more benefits than downsides. You may also organize a matrix to be more GPU friendly by transposing the fields directly into the matrix struct (SharpDX is not doing ...


1

i recently resolved a similar issue by doing as bummzack suggested in his comment. the gui element is going to try and draw the nameplate on a 2d plane in front of the camera regardless of the direction its facing. you need to stop it manually void Update () { Vector2 temp = cam.WorldToViewportPoint( target.position + offset ); // check if ...


1

As you may have noticed, the Update function is executed every frame as long as the MonoBehaviour is enabled. You can assign a constant velocity to the Rigidbody of the square instance in the Update function, so it moves at a constant velocity every frame. if (grounded) { if (Input.GetKeyDown(KeyCode.Space)) { rigidbody2D.AddForce(new Vector2(0, ...


0

public GameObject newSprite; private Vector3 currentSpritePosition; void Start(){ newSprite.renderer.enabled = false; } void OnMouseEnter(){ //getting the current position of the current sprite if ever it can move; currentSpritePosition = transform.position; //then make it invisible renderer.enabled = false; //give the new ...


2

Coroutines aren't threads or processes or anything special like that. They're just callbacks given to the engine to call when a specific condition is met. If you yield null, the coroutine will be called every frame. Every frame, the engine calls all coroutines that are ready at that time, all together in a block (either right before or right after calling ...


4

Flip a switch depending on the walls' collision face: bool runForwards = true; public void WallCollsionHandler(Collider collider){ if(collider.tag == "Left Facing Wall") { runForwards = false; // Or // JumpBackwards() } else if(collider.tag == "Right Facing Wall") { runForwards = true; // Or ...


2

If your platforms are isolated use Tags. Each object and prefab in the Unity game world can be interacted with differently depending on the tag they have. For a wall of any kind simply tag it as "Wall" and code it with this is mind when making collision detection on your main character. For a platform, guess what, tag it as "Platform". You can then ...


-1

Define an interface IWall. using UnityEngine; using System.Collections; public interface IWall { void OnCollisionEnter(Collision collision); } It is nice to separate the vertical and horizontal walls in to two classes as their logic for handling collisions is different. VerticalWall using UnityEngine; using System.Collections; ...


1

You can make use of the AssetPostProcessor to post-process your assets in Unity Editor. Here is an extract of the code I used in a project before. using UnityEditor; using UnityEngine; using System.Collections; public class MyPostProcessor : AssetPostprocessor { public delegate void PostProcessAsset(); public static event PostProcessAsset ...


1

SerializationException: Type UnityEngine.GameObject is not marked as Serializable. That means UnityEngine.GameObject is not marked with the Serializable attribute, which is a requirement (just because Unity says a type is serializable doesn't mean it's serializable with all serialization engines; in this case, it probably means that the type is ...


0

You can use only the distance, without use the sqrt and the Pow because the distance is usually calculate with this formula: float dist(vector3d v1, v2) { v.x = v1.x - v2.x; v.y = v1.y - v2.y; v.z = v1.z - v2.z; return sqrt(v.x*v.x + v.y*v.y + v.z*v.z); } as you can see here.


4

This is most likely down to the frame rate, which makes me wonder how can I make sure that a coroutine takes the precise amount of time it should take despite the fluctuating frame rate? I don't think you can, honestly. Coroutines are at the mercy of Update() in the same way the rest of your code is. You can't make it end between two update loops, ...


0

You can load resources from a folder called "Resources" using this: Texture texture = Resources.Load(textureName); guiTexture.texture = texture; Nice and simple. If you want to find a particular texture using a named reference you can use: Texture texture = Resources.Load(textureName); GameObject.Find("NameRef").guiTexture.texture = texture; You can ...


2

You can do this using plain mouseup/down tests and raycasting, and the same pattern applies to many other situations, like marquee selection. // Call this inside an Update method. void HandleDragging() { const int mouseButton = 0; // button values are 0=left,1=right,2=middle if(_isDragging) // Leading underscore denotes private member variables ...


1

When you start drag (OnMouseDown), save object position in some variable. Then OnMouseUp you can test that object is in position you needed else restore object position by saved variable. UPD: // Define some target to place object in. It can be any Collider public Collider target; // Variable for saving initial object position private Vector3 ...


0

You can never make sure a coroutine takes a precise amount of time. As you said, it's the frame rate. You can get super close, but it'll never be spot on. The time between frames will always differ, based on hardware. Thus you will almost always overshoot your specified time. Imagine you are at 4.89 seconds and the next frame takes 0.16 seconds to update. ...


2

One thing I've done in the past for island shapes is to use perlin noise minus a circular shape. It usually produces one big island and some little things off on the side. You can use flood fill or smoothing to remove any small noise. Here's a demo (flash) that I wrote for this question. For each location (x, y) in the noise bitmap, compute the distance ...


0

Actually it is normal if the dvalue is under 0.01. And that 0.01ms won't bother your game. I've tested. That 5 second will be different each time you launch the game.


2

I believe you want something like the below. It will keep track of the most recently pressed key in the variable _movementKey and set the movement key to none when the most recent key is released. So the end result should be _movementKey contains the key that dictates direction, it will always be most recently pressed key and will be reset to Key.None when ...


0

Behavior Trees are a great way to structure your behavior, but they can suffer from excessive "checking", as you point out. By design, a BT will jump to another branch in the tree if a higher priority behavior becomes available, so the implementation needs a way to check if that's the case. The easiest and safest way to do it is by polling. The BT will ...


0

This is how you do it! Invoke("ChangeMaterial", 2); // Time is 2 seconds function ChangeMaterial () { /* Change Material */ }


0

You have to use OnCollisionEnter2d() method here so collision detection happen for one time only. If you want any collision detection then there is no requirement of rigidbody. If I can't able to understand you question then ask it specifically.


1

As stated in other answers Unity 4.x uses a modified version of Mono based on Mono 2.6 For the most part, this is compatible with the .Net 2.0, though I haven't managed to track down a Mono 2.6 specific compatibility list. It looks different from regular C# but there are some regular C# elements in there. As mentioned in one of the comments on your ...


0

Stacking Issue Regarding the stacking issue, I am not sure how your class is setup, but I would consider handling the positioning of the stacked elements based on an indexed approach. For Instance (pseudo code): class Skewer : MonoBehaviour { public List<SkewerElements> skewerElements = new List<SkewerElements>(); public float ...


0

Every game has different design challenges. I would start by drawing out a flow diagram of events. A Behavior Tree typically uses high level "composite" nodes. You can then build out these "composite" nodes into sub-trees. For instance: [sequence] --> [Am I Under Attack?] --> [Flee] The nodes "Am I Under Attack" and "Flee" are composite nodes. You ...


0

You can convert viewport space coordinates into world space coordinates using Camera.ViewportToWorldPointSwitch and use the returned position to instantiate your smoke particles at correct position.


1

The strategy we will follow is bounding the derivative, as the technique of splitting the query regions is very complex and probably very slow. Consider first a 1D function f, for which everywhere, |f'| < 0.3. We are given that f(3)=-2. What is a bound for f over the interval [1, 5]? Looking at the derivative bound, we have: | df | | -- | < 0.3 | dx | ...


-3

The question whether the C# Version used by Unity is different from a "regular" C# has been answered by other posts. Since you are explicitly asking for certain elements which might differ from such a regular version I will share the only minor difference I noticed when comparing the C# I use at work (i.e. C# 4.0 in Visual Studio 2010 and higher) and C# in ...


-3

Some elements of the UnityEngine package conflict with standard C# naming, so it makes it appear to be different. However, as others have said, it is regular C#.


17

Unity 4 uses Mono 2.6, which is a full implementation of the .NET framework, including the C# language. I'm not sure how it looks different, but keep in mind that Unity supports several languages, all of which work on top of the same Mono runtime. Is it possible you're confusing C# with UnityScript?


3

Unity uses regular C#. Then again, when you write C# in Unity you will be using a lot of their libraries, but as far as I know, everything possible in C# is possible in Unity, other than the differences listed below: More specific areas of .Net relating to Windows Forms & ASP are off limits through Unity. While you can use Visual Studio for editing ...


0

The proper way to make this 'knockback' movement is by applying an impulse on the knocked object. The impulse will be in the direction of the velocity of the hitting entity (the projectile), scaled to some number that fits your game (that should probably take into account the masses of the two objects). To make the entity slow down gradually after the hit ...


1

glampert solution is very complete, but I will add my personal experience. I ran into this same problem, and my solution was to use an static Variables class. The Variables class internally keeps a map from string to string (so far all my variables are only strings) and is accessed via getters and setters. The point is that getting access to global ...


1

First code, code the normal movement of the character to progress a constant distance toward the target position every frame (ie. inside the Update() function). Then put that movement code inside an if statement for if the character is being knocked back. Only move toward the target if not being knocked back. If being knocked back, move toward the ...


1

Here is working example of Monogame + WPF interop: http://panthernet.ru/forum/index.php?/topic/21-monogame-wpf-interop-application/



Top 50 recent answers are included