Handle touches not started on the UI

I seek a way to handle touches that do not start on UI elements in Unity Engine …But if the touch down event is on any of the UI elements it shall be handled by that UI element instead of the map. The IsPointerOverGameObject function is used to simplify this. If it returns false, do … Read more

Change colors of UI button via script

You have to change the colors not the normalColor. The GetComponent<Button>().colors returns ColorBlock. So, create a new instance of ColorBlock. Modify normalColor from that ColorBlock then assign that ColorBlock to the GetComponent<Button>().colors. Full example: ColorBlock colorBlock = new ColorBlock(); colorBlock.normalColor = new Color(0.0f, 0.0f, 0.0f, 1.0f); prev.GetComponent<Button>().colors = colorBlock; This will overwrite your other color … Read more

WWW/UnityWebRequest POST/GET request won’t return the latest data from server/url

This is happening because resources caching is enabled on the Server. Three possible solutions I know about: 1.Disable resources caching on the server. Instructions are different for every web server. Usually done in .htaccess. 2.Make each request with unique timestamp. The time should in Unix format. This method will not work on iOS. You are … Read more

Download AssetBundle in hard disk

This is not really complicated. Handle it like a normal file you would download from the internet but save it with the “.unity3d” extension. 1.Download the AssetBundle as a normal file by making a request with UnityWebRequest. UnityWebRequest www = UnityWebRequest.Get(url); yield return www.Send(); 2.Retrieve the byte array data with DownloadHandler.data then save it to … Read more

Use coroutine inside a non MonoBehaviour class

TonyLi mentions that you can pass a Monobehaviour to start and stop coroutines inside a instance of a class, but he does not show how you can do that. He does this You are can do that with the this keyword. The this keyword will get the current instance of MonoBehaviour. In this example there’s … Read more

Build C++ plugin for Unity

You are trying to load UWP plugin in a non UWP environment and this is because of the way you build your dll. This post describes how to create, compile and build C++ plugin in Unity. Software version used for this (should work for other older versions too. This information is mentioned just in case … Read more

Unity 2d jumping script

Usually for jumping people use Rigidbody2D.AddForce with Forcemode.Impulse. It may seem like your object is pushed once in Y axis and it will fall down automatically due to gravity. Example: rigidbody2D.AddForce(new Vector2(0, 10), ForceMode2D.Impulse);