Tag Info

New answers tagged

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/


1

There are a number of tools for this purpose. Flash itself has an option for something like Export to PNG Sequence. Texture Packer also can import a SWF. Yet another option, which I used to create the spritesheets for the HTML5 demo on my site, is Zoe, the spritesheet tool that comes with CreateJS.


1

I'm guessing you mean "Flash Pro". You can export a sprite sheet directly from inside Flash Pro. Instructions are available on Adobe's web site. http://helpx.adobe.com/flash/using/create-sprite-sheet.html This will take a snapshot of each frame of the animation, at the interval for the frame rate you specify, then combine all the frames into a grid in a ...


22

Hardcoded 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. Not just that, but many times you will want to change settings while the game is running. You can't do that with hardcoded constants. Once your project grows, you might want to ...


4

Well first off an enum defines what the values can be, not what the values are. Thus you still need to declare another variable after you've declared the enum. For example: public enum Sound { ON, QUIET, OFF } public Sound soundValue; In this example, you can now set soundValue to ON, QUIET, or OFF. Then you still need to structure your ...


0

Found the problem. XNA's content pipeline doesn't seem to be able to handle animated FBXs correctly. So XNA has a bug. Luckily Blender 2.68a and older has a "fix" for this. Just check "XNA rotation animation hack" when exporting the FBX.


1

The BayazitDecomposer class was made assembly-internal in commit 101497, which was aimed at centralizing the input validation for the triangulation algorithms in a single place according to the check-in comment: Removed sanity checks from all triangulators and moved them into Triangulate. Added asserts into each triangulation algorithm that checks if ...


8

For newcomers to this question, it looks like Microsoft has put up XNA installers for Visual Studio 2010/2012/2013. I haven't personally tested to make sure these work, but they might be worth a look: https://msxna.codeplex.com/releases/ EDIT: After running all included installers for the Visual Studio 2013 release (running VS 2013 Ultimate on my ...


1

You might try using Flump: http://threerings.github.io/flump/ You'll have to port one of the existing client libraries to Unity, but the client libs are simple and should be pretty easy to port. Most of the heavy lifting is done by the exporter.


1

While not exactly what you're looking for, this post on reddit might be of interest - an upcoming tool for rendering swf animations in Unity, from the sounds of it the performance is good and you still retain the cross-platform functionality.


3

Have you tried using ShoeBox it has many utilities for SWF files. One of those allows you to create spritesheets from a SWF file.


0

If you're not dead-set on flickering, there's a simple solution to this, which is to use a trig/wave method (like sin or cos). These will produce a continuous, even oscillation (which, at a high enough frequency, may appear similar to flickering). I don't know enough about Unity to suggest why it didn't work. What I think is that you're probably using total ...


0

First off CRT and LCD are different in may ways. Though I'm not sure how their refresh rate changes. I can say, with absolute certainty, that their difference in refresh systems is not something that is used. Nor is it something that you can change, or something that will be effected by game-code (aside from maybe adjusting the refresh rate, if you felt like ...


1

There is no built-in function. You're using MonoGame, so you could just modify the MonoGame source to do exactly what you want. You could also use reflection to get access to the internal SpriteBatch member that holds the current count. In XNA it's the spriteQueueCount field. MonoGame seems to be more complicated - look at the source code to determine what ...


1

You need only simple collision detection for something like this: You could just compare the X-coordinate of the nearest wall with that of the player when the player throws a punch. Something along the lines of if (wall.x - player.x <= 50 && wall.x - player.x > 0) { // The wall is in a good position! } else { // The wall is out of ...


4

The very first question all beginning Unity developers have is C# or JS. Always go with C#. Now, right now you may be thinking, "But I don't want to learn C# and I already know a bit of JavaScript." But the misleading thing you need to consider is that Unity JavaScript is not JavaScript. It is a superficial veneer of ECMA syntax over .NET CLR. It does not ...


0

There are a couple things you will need to do here I believe: 1 Sorting the objects based on rendering order because they have a "Z component" 2 Translating the world coordinates into screen coordinates/scale by account for camera position 2 Touch up art assets that have a "depth" or "thickness" when portrayed in 3d space.



Top 50 recent answers are included