Hot answers tagged

6

Check if Touch TouchPhase is Stationary, which even says will be set only if: A finger is touching the screen but hasn't moved. I suggest you also read up on the Touch.phase property, which exposes the TouchPhase for the specific Touch. The link also has examples on how to use the phase. The other option is to check the deltaPosition of the Touch. If ...


4

I think what you are looking for is something like following: GameObject CreateText(Transform canvas_transform, float x, float y, string text_to_print, int font_size, Color text_color) { GameObject UItextGO = new GameObject("Text2"); UItextGO.transform.SetParent(canvas_transform); RectTransform trans = ...


3

The mechanical difference is that Lerp is linear, while SmoothDamp follows a sigmoid function. See How to Lerp like a pro and Smoothstep for more in-depth explanation and graphs. In terms of which one you should use, that varies from product to product, situation to situation. SmoothDamp-style is often more pleasant to the eye, especially for slower fades ...


3

You need to bake a navmesh first.


3

You want the 2D version of the method: OnCollisionEnter2D Collisions with a Collider2D/Rigidbody2D won't send the "OnCollisionEnter" message, only "OnCollisionEnter2D"


3

using UnityEngine; using System.Collections; using System.IO; public class ScreenshotNow : MonoBehaviour { public RectTransform rectT; // Assign the UI element which you wanna capture int width; // width of the object to capture int height; // height of the object to capture // Use this for initialization void Start () { width = ...


2

If you are looking for a quick&dirty solution for debugging, you can still use the old Unity 4 solution. Implement the OnGUI event of any MonoBehavior you have always active to call the GUI class to add some UI element to the current rendering frame. void OnGUI() { GUI.Label(new Rect(10, 10, 100, 20), "Hello World!"); } If you want to use the ...


2

1 do you mean you want change the uitext dynamically? If you want to change it, first u have to attach your script to gameobject. Then bind your variables. Tutorials could be found here transform.gameObject.GetComponent<Text>().text = "123"; 2 If you want to create uitext which is not in Hierarchy beforehand. You could use GUI. GUI Label Put ...


2

Instead of pathing from each new enemy to the player as they spawn of the player moves significantly. Do a floodfill from the player to fill the entire map with how far the player is from each tile and which way he is. Then for pathing you just follow the arrows. The floodfill Will only need to update the neighbours of the tiles whose value changed after ...


2

As your desired image reflects that you want it in 2D, so I have modified your current script which would draw a path from your given Game Object, decided start position, mouse or finger position would be the end position. Other than that you can specify number of elements should be drawn on the path. Well, have a look and give it a try. Comments will also ...


2

Another option might be to split the class into two parts: a regular static class for the Singleton component, and a MonoBehaviour that acts as a controller for the singleton instance. This way you have full control over the singleton's construction, and it will persist across scenes. This also lets you add controllers to any object that might need the ...


1

So, I did some googling and according to another question it should work online with one exception : Basically there are no hard limits, with exception of WebPlayer, which is limited to a 1 MB. Source : http://answers.unity3d.com/questions/182755/playerprefs-lmitations.html


1

In C# when a struct is accessed via a getter (like transform.position), the compiler won't allow you to modify a member, because it has no sense to do that, because a getter of a struct return a brand new struct that you have to reference first. If you don't your brand new struct will stay inaccessible...


1

I can't type in a location without all the selected boxes going there (so if I type a y-location of 12, every single selected box will be crammed on top of each other on y=12) This issue is easy to fix: Select all boxes and duplicate them. Put them inside new empty parent GameObject. Translate that GameObject by needed distance. Take boxes out from ...


1

It's not a perfect solution (I hope others can suggest general-purpose tools for this), but I usually do this with keyboard shortcuts: Ctrl + D to duplicate the currently selected objects select all of them Hold Ctrl and drag the translation handles to move them, snapping to 1-unit increments So I start with one object, dupe-move it to get 2 one unit ...


1

Let's assume your Unity project is in: C:\Users\me\Documents\Unity Projects\My Voxel Project\ (If you don't already have a project, start by opening Unity and clicking "+ New" when it asks which project you want to open) Now, copy the contents of the tutorial to: C\Users\me\Documents\Unity Projects\My Voxel Project\Assets\ You can create additional ...


1

Input.GetButton() instead of Input.GetButtonDown() The former checks to see if the key is currently down and outputs true for every frame during the press. The latter checks to see if the key was up last frame and down this frame (that is: true for exactly one frame until released again).


1

you can publish different versions of your APK targeting different CPU architectures, with the same package name: Build an ARMv7 only package and an x86 only package with different version codes. The versionCode of the x86 package has to be higher than the one of the ARM package. When publishing, send both of your APKs to the developer console. Note that ...


1

I'll throw my singleton into the mix. It checks off all four of DMGregory's criteria (see his answer). This has a lot of stuff that may not make sense. It is just covering Unity specific corner cases, and persists between scenes. It is tried and tested, and the most current version can be found on my Github. Enjoy! Usage is by having your script extend this ...



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