When building a Unity program for web (WebGL), mostly we need to access methods/functions inside Unity from JavaScript (browser scripting). This example is showing how it can be done. In this example I’m showing how to call JavaScript alert from Unity and then send back some string text to Unity Scene from web browser.
Category: Unity
How to set a texture of a Game Object from URL in Unity3D
I’ve searched for this thing recently on internet and I found a way to set a texture image from URL to a game object in Unity3d. Here is the script, you can attach this script to your GameObject, but don’t worry to specify your desired URL on the inspector.
Creating crowd cars that move along given waypoints in Unity3D
Sometimes we need to create some dummy crowd cars that move from a point to another points to fill up the scene with fake traffic system. This script, which I call it WP Patrol is able to move any object, let’s say a car, to any specific points (way points). But please note that this…
How to prevent a camera from going inside any collision object in Unity3D
Sometimes when our camera moves, it goes inside an object like wall, tree or any other object. How to prevent that? This is very simple solution, you can try it wit a few mouse clicks. The solution is to add a collider and rigid body components to the camera. Watch this video to see how…
Another tutorial about Smooth Camera Follow in Unity
Hi, previously I’ve made a tutorial about how a camera can follow an object smoothly in Unity. That tutorial was in this link: https://www.youtube.com/watch?v=3QbHSlC5a3o But seems some have problem, they said camera movement is shaky and laggy. So, here is another tutorial, this time I exported my scene and script as a Unity package, so…
How to create day and night cycle in unity
In this tutorial I will show you how to crate a day and night cycle in Unity just by animating the direct light and using it as the sun. You will also see how to create dynamic lights that can be switched on on night time and switched off on day time. Watch this tutorial:
How to create a simple moving train locomotive and wagons in Unity3D
In this tutorial you will see how to easily create a moving locomotive and wagons along the spline track in Unity3D.
How to Pause and Resume game in Unity3D
How to create pause and resume button for our Unity games? It’s easy. In this video tutorial I will show you how to set up the Pause and Resume UI.
How to create simple menu navigation and switch between menu screens in Unity
I’ve made a step by step video tutorial to create a basic menu and navigation script in Unity3D. So basically you can see the Main Menu with two buttons to navigate to its sub menus, and in each sub menus you have a back button to go back to Main Menu. In this video you…
Enemy Patrol Starting from the Nearest and Closest Waypoint in Unity3D
I’ve created a simple C# script for Unity game that allows you to create a patrolling enemy around multiple waypoints (check points). It will start patrolling from the nearest / closest waypoint available around the patrolling object, then it continues to check the next waypoint incrementally. Watch the tutorial video on my YouTube channel and…
How to add a Virtual Joystick in your Unity game easily
In this video I’m showing how to add a virtual joystick in your Unity by importing this package called MyJoystick. See how to use this package in this video and have fun. Here is the link to download the package, it’s from my Google Drive: https://drive.google.com/open?id=1KPUvXeJQw_XATMTY0QmF_4JE0-05sHQy That is a Unity package. Drag and drop it…
How to move an enemy towards the player in Unity3D
When you make a game, you often need to make enemies that move towards the player. In this video I’ll share some method to move an enemy object towards the player in Unity3D. Watch this video to see how to do it by creating a simple script: And here is the script used on this…
How to animate a texture in Unity3D
Instead of animating texture itself, we can animate the coordinate of the texture by script in Unity3D. In this video tutorial I’ll show you how we can animate a texture in Unity3D. Here is the script I used in the video:
Preventing multiple same ElectronJS apps to run at single time
I am building an EelectronJS app and successfully release it as an executable Windows program. But the problem is when the app is already running, if I double-click again that .exe file, the second window of this app is running, but buggy. I don’t want it. So here is the solution:
How to : Camera Follows Player Smoothly in Unity3D
Hi, in this video I’ll share with you some useful C# script for your Unity3D game camera so your camera can follow the player’s movements smoothly. Watch this video:
How to switch between multiple cameras in Unity3D
Let’s say you have three cameras in your Unity3D scene. So how do you switch between them? In this video I will show you how to do that.
Basic Unity and Client-Server Request-Response with PHP
In order to make our Unity game connected to the online world, it must be able to send requests to and get responses from our server. In this tutorial you will see the basic way to make our game able to communicate to PHP server side script.
Changing the skybox material programmatically in Unity
I’m using this simple script after attaching it to UI Buttons to change my skybox materials. Let’s say we have two skybox materials with two UI Buttons to switch between them. Here is the script: using System.Collections; using System.Collections.Generic; using UnityEngine; public class ChangeSky : MonoBehaviour { public Material sky1; public Material sky2; public void…
Unity click and drag script to rotate camera
Just googling around to find how to rotate camera with mouse click and drag. Thanks to this link: https://answers.unity.com/questions/1189946/click-and-drag-to-rotate-camera-like-a-pan.html This code is originally taken from that link: using System.Collections; using System.Collections.Generic; using UnityEngine; public class CamRotate : MonoBehaviour { public float speed = 3.5f; private float X; private float Y; void Update() { if(Input.GetMouseButton(0)) { transform.Rotate(new…
Solving mach-o linker error on publishing Unity – XCode
One of common error when we want to build our Unity game from XCode is this mach-o linker error. There are many solutions on internet but in my case, the solution is this simple one: Change target build to 8.0 On Build Settings, set Enable Module to Yes and Enable Bitcode to No.