Tag Info

Hot answers tagged

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?


6

It might be silly, but you could make a small C++ program around the chess library, that takes a simple text board state or movelist as input and returns the AI's selected move. I don't know .net's system libraries off hand, but you can probably start it as a subprocess, send to its stdin and then poll its stdout for a reply. Local sockets are also a ...


6

Don't forget that every object in .NET has a ToString() method. Many of the built-in value types accept an optional formatting argument; numeric types in particular are easy to format with standard formatting or custom formatting. For example, instead of just passing cur_health, you could pass cur_health.ToString("n0"). For the specific question, you could ...


5

For 3D, Unity uses PhysX. According to this answer, PhysX uses a symplectic integrator. The paper it cites as evidence is a bit more ambiguous though: Since it is a commercial engine the implementation details are unknown ... Most physics engines provide results similar to the Symplectic Euler integrator, or 2nd order Euler. Novodex (Ageia PhysX) ...


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


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


4

I will assume that you have a function f such that the surface is defined by f(x,y,z)==0. Right now, all you have is the function f itself, and so with no further information, it is impossible to know when to subdivide. It is always possible for the surface to do what you describe, i.e. the function f can have arbitrarily thin "fins" which can require you do ...


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


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.


3

Create an invisible box in front of the fan. Then check if some object is inside that box. Apply movement to that object. This can be done in unity quite easily. Create Empty gameobject Select the new gameobject Add Component-> Mesh -> Mesh filter Select from inspector -> Mesh filter -> mesh and set it to "cube" ( or what ever shape you want ) Add ...


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


3

There are a variety of ways to run code written in other languages in Unity. Most of these are platform specific. iOS: Since xCode will also compile C++ code, you could add the C++ code to the plugins directory and it will be built when you build the iOS app. You'd then define the function prototypes in C# so they are accessible from Unity. Documentation is ...


3

You need to add a BoxCollider2D component to your GameObjects. http://docs.unity3d.com/ScriptReference/BoxCollider2D.html From the Unity docs for OnCollisionEnter2D Sent when an incoming collider makes contact with this object's collider A Rigidbody2D just tells a GameObject how to interact with the physics engine. It doesn't provide a collider for ...


3

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


2

Just go really simple. Add a flag to the player that tells the camera when they're jumping. If they're jumping, don't follow them up. The other situation you need to handle is when the player jumps up or down to different levels. In this case it would be pretty simple to start tracking again when the player touches down, or if the player goes below the ...


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


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


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


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


2

To begin with, in order to access and update your board with ease, you can make use of the Dictionary<Key, Value> class together with the Vector2 structure defined by Unity. Dictionary<Vector2, Tile> tiles = new Dictionary<Vector2, Tile>(); Tile is a class defined by you. It should contain information such as its coordinates on the ...


2

A good algorithm to generate any kind of solvable puzzle is to first generate a solved configuration of the puzzle, and then backtrack a number of valid moves which would lead to this configuration. You can easily control the difficulty by how many moves you perform and you have a valid solution to it. However, keep in mind that there could always be a ...


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() { ...


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

Well, from you code I see that in line: cs.itemAvailability[j] = (int)tilemap[i*numberOfColumns+j]; cs.itemAvailability is definitely null. You declare an array variable but it's never initialized. You need something like cs.itemAvailability = new int[size_of_array]; if you want it to be an initialized array.


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


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


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


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

Save the linear velocity and angular velocity. Then zero them out on the rigid body. The reapply them when you're ready for the body to move again. Something like a coroutine will work just fine (mine is written in C#, but you can convert it easily enough): void Update() { if (Input.GetKeyDown(KeyCode.T)) { StartCoroutine(PauseMovement()); } ...


1

You add a constant force by doing pretty much what you're doing already. The problem you're likely having is a debugging one, or your expecting more force to be added then you're actually adding. Keep in mind that if you want the force to affect the object, you'll probably want to apply a larger force when the touch has ended. Remember that how much the ...



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