Tag Info

Hot answers tagged

12

The only possible yield values the scheduler understands are: Classes derived from YieldInstruction (WaitForSeconds, WaitForEndOfFrame, WaitForFixedUpdate, AssetBundleCreateRequest, AssetBundleRequest and Coroutine a WWW object "any other value" which isn't one of the above. If "any other value" is yielded (which includes "null" a ...


9

When working with Unity you have to do some work within Unity's editor; that's simply how Unity works. However the vast majority of what you'd be doing as a programmer doesn't happen within Unity's editor; the script files are external text files written in an external IDE, and as a programmer you only use Unity's editor for linking which scripts to run and ...


8

Would this be a good place for inheritance? No, this is a good place for composition, see the Strategy pattern for more details. First of all, define an interface for your skills. Each character will have an instance of a class that implements that interface as a member. This ensures that you can switch between skills at runtime with ease. A simplistic ...


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


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

Apply any transformations inside the Update() method, rather than FixedUpdate(). Fixed update runs independently of your framerate, and this will inevitably cause stutter. Think that there may be a number of frames displayed without any call to FixedUpdate() in-between (the update is performed "late"). Aside from dealing with rigidbodies, you should have no ...


5

Found it! Attribute [ExecuteInEditMode] does what I want [ExecuteInEditMode] public class RandomRotation : MonoBehaviour { void Start () { #if UNITY_EDITOR this.transform.Rotate(0, MyRandom.Rotate(this.GetInstanceID()), 0); this.transform.localScale = MyRandom.Scale (this.GetInstanceID(), 0.4f, 1f); Debug.Log("Editor"); #else ...


5

This fully depends on the developer at hand and how well the person knows the coding language. Assuming you can definitely do the art side of things, I'll go ahead and list some pros and cons of both engines. Game Maker Studio: Pros: Very, very fast prototyping. Very beginner-friendly coding language called GML. Extremely welcoming community. Cons: ...


5

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


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


4

To be able to select objects in Unity, you need to add colliders to your objects. Just dragging the model into the scene will not automatically add a collider. For each game object you want to interact with, select it in the Hierarchy and add a MeshCollider using the Inspector. Now, create a script that will display interact with the objects, something like ...


4

Yes it matters but there's no general rule, it depends on the specific scenario and requirements. Here's some hints: 1 Mesh Scenario Pros: Reduce drawcalls(state changes). Cons: No occlusion culling(it's done on a per GameObject resolution in Unity) Potentially time consuming updating the required vertices (depends on the geometry complexity, but ...


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

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


3

There are several different events that can be called from the interstitial, AdLoaded, AdOpened, AdClosing, and AdClosed. Unfortunately it appears this is as much interaction as you can have with the interstitial that google exposes. Digging deeper, if we look at the source of InterstitialAd, then we find it inherits from IAdListener, which only exposes the ...


3

Unity Remote exists for this purpose. Quoting their description: Unity Remote is an application that allows you to use your target device as a remote control for your project in Unity editor. This is useful during development since it is much quicker to test your project in the editor with remote control than to build and deploy it to the device ...


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


3

Considering you have a while(true) loop in your code, you're not going to allow the game loop to move to the next frame. You'll need to move to the next frame to update the screen and gather new input. You can use the void Update() method to check for stuff like keyboard input every frame. void Update() { if(Input.GetKeyDown(KeyCode.W) | ...


3

unfortunately in my travels i have not yet found a way to do this, and afaik i haven't seen an add-on to specifically do this either. what i have found is an interesting answer here... of a possibly useful alternative solution... there the op goes into modifying the editor with some custom scripts to enhance the "create script" menu options, essentially ...


3

I don't know which is the specific error in your case, but at least from my experience, I'd use quaternion instead. You can just lerp between your current camera rotation and the desired one. Something like: transform.rotation = Quaternion.Lerp(transform.rotation, player.transform.rotation,Time.deltaTime * speed); In general quaternions offer a simple and ...


3

I believe what you are looking for is the Futile Framework for Unity. Basically, you can then do all your programming using scripts without having to "drag and drop" stuff or mess with the visual editor much. All you need is a single GameObject in your Scene which will be the container for your entire game. You then do everything procedurally as you would ...


3

The usual tricks with weapons are: Make your character's collider large enough that it contains your weapons, then simply ignore collisions between it and the weapon's raycasts. Make it appear not to go through by drawing it on top of other objects. This works for FPS type games: Put the weapon(s) on a new layer (for this example it will be named ...


3

I did the following to achieve results: Added a Rigidbody2D to the player (deactivate Gravity). Added a 2D-Collider to the bomb. Added control and health script (basic stuff, just position updates). My health is just a public variable. Used the following code in playerPhysics.cs: void OnCollisionEnter2D(Collision2D coll) { if (coll.gameObject.name == ...


3

Check your Unity Preferences / External Tools / Android SDK Location, according to the Unity docs regarding Android SDK Setup. Check your Build Settings (it's important to check that you've added all the scenes and the starting scene at the beginning) Write down the name of the apk file and click save You should see a new window for showing the building ...


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

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

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



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