Skip to main content

Posts

Showing posts with the label Unity3D

Which all files and folders to backup to zip a Unity Project

  In order to be able to recreate the Unity Project from a backup zip, just remove Library and Temp folder when backing up the project to a zip file. This will significantly reduce the zip size.

How to drag and drop item in Unity3D

  For dragging and dropping to work we will need to first grab the Game Object and ensure while the Game Object remains grabbed it's position reciprocates the mouse position. This will work fine for not only PC bug mobile devices as well. First define GameObject which we will be dragging. public GameObject selectedPiece; Now inside Update method we will give reference to touched/clicked object and while there is a reference available to an game object(selectedPiece;) we will move that object to mouse position. When the reference is remove, object won't move therefore dropped. void Update(){ RaycastHit2D hit = Physics2D.Raycast(Camera.main.ScreenToWorldPoint(Input.mousePosition), Vector2.zero); if (Input.GetMouseButtonDown(0)){ if(hit.transform != null)             {                 if (hit.transform.CompareTag("PIECE"))                 {     ...

How to convert String To DateTime In Unity C#

How to fetch Day, Month or year from date time string? How to get Hour, minute or second from a date time string? Following snippet of code can be used to deal with most of the forms of date time string in Unity C# Instead of having time in the form of   "2020-1-31 12:10:15"  you can also pass "31/1/2020 12:10:15 PM" and or any such case of Date time in string. Then from this DateTime object you can fetch any particular detail like Year shown in example below. System.Globalization.CultureInfo culture = new System.Globalization.CultureInfo("en-US"); DateTime tempDate = Convert.ToDateTime("2020-5-6 12:10:15", culture); Debug.Log("Testing date time conversion: " + tempDate.Year); This could be used to deal with date time strings of the form   "dd:MM:yyyy HH:mm:ss" "yyyy:MM:dd HH:mm:ss"

How to make neon light signs in Unity 3D

As part of my game, I was trying to create a whole apartment like environment. I decided to call it a motel instead. So I had to put a sign saying it's a motel( how else would people know right? ) To create the simple glowing text you need text mesh pro. It's available in Asset Store as well as in Unity Package manager. Inside Unity, go to Window > Package Manager and search for text mesh pro. Now go to Game Object > 3D Object > Text Mesh Pro Text Now enter whatever text you want and select distance field shader in text mesh pro inspector tab. See image below. Once selected you'll be able to see a number of settings under shader and can enable glow from there. I'd recommend playing with numbers here to suit your scene.  Now that you have your glowing text if you want more you'll notice they seem to be using the same shader which will cause a problem if you want glow signs in different colours. For this, we need to creat...

Making Sensor Lights in Unity 3D

Lighting in Unity 3D can some times get tricky. I just spent hours into making sensor lights only to come up with a very obvious solution. At first, I was using baked maps which were the primary reason for my trouble. I know it's kind of obvious but I need to state it for anyone who is struggling with the same. Don't use Baked Lightmaps if you want real-time illumination. As simple as that. I even considered lighting up the environment by real-time switching different lightmaps. Thanks to the complexity of such task I didn't do it. Finally, the solution was to use simple point lights. To give the lights better look I used emissive materials. Here are the results.         Here's how I did it. Created an empty Gameobject Light Controller and under that created two small cuboid, LightsOn and LightsOff and a point light called Bulb here. Added a box collider in Light Controller and ticked Is Trigger .   Here's the script attached to the Light...