Showing posts with label C#. Show all posts
Showing posts with label C#. Show all posts

How Unity call it's MonoBehaviour Method or Events like Update

 Ever wonder how the magic events of unity Behavior works:

void Awake()

{

 

}

 

void Start()

{

 

}

 

void Update()

{

}

// Or other unity magic events like OnEnable, OnDisable, Late Update, Fixed Update, etc.,

The simple answer comes into mind that maybe unity use reflections to find Mono Behaviour methods in order to call it every time or maybe they use override to those methods but apparently, this is not happening. So how it calls its event especially the Update event that calls on every frame.

The way unity3d Messaging system works its:

1.      Unity scripting runtime Mono or IL2CPP access MonoBehaviour derived (type) script.

2.      Look for magic events and cache it.

3.      Like if a MonoBehaviour derived script has an update event then the script will be added into a list (list of scripts) that will be updated on every frame.

4.      Now during gameplay, unity iterates over the list and fire the Unity events. This is the reason that if you make your event public or private they don’t get effected.

 


Unity WebGL Technical breakdown - How Unity WebGL Works

 A Glimpse of technical background of unity3d WebGL:

Unity support dozen of platform for application deployment and one of them is WebGL. WebGL allows you to run your content on a web. Technically, WebGL is an API that renders graphics in web browser.  Currently, it has two supported version of WebGL 1.0 and 2.0. Remember WebGL 1.0 roughly matches the functionally of OpenGL ES 2.0 while WebGL 2.0 roughly matches the functionally of OpenGL ES 3.0.

Unity WebGL Structure


Figure 1 Unity WebGL consist of these components.

Remove Empty Unity Events - Do Empty Unity Events cause Performance Issues?

      You definitely have noticed this thing that whenever you create a new script in Unity3D, the Unity scripting template adds two methods or unity events by default. The two methods are Start () &Update ().
using UnityEngine;
using System.Collections;

public class MyCustomScript : MonoBehaviour {

	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
	
	}
}

Control Object Transparency with Slider UI in Unity

In this unity game development tutorial you will learn how to control decrease or increase GameObject transparency/alpha or opacity. With the help of a slider and a C# script. I will explain how to increase or decrease opacity of an object using a c#  script. 

How to make Object Transparent in Unity3d with Script C#

C# Beginner Tutorials in Urdu/Hindi


I have started C#.Net tutorial series in Urdu/Hindi language and here are different lectures with the order.


1. Visual Studio Programming Environment Intro & First Script Execution

2. Visual Studio Programming Environment Intro & First Script Execution

3. Why start learning C# with Console Application Development

4. Variables in C# - int Data type - C# Beginner Tutorial Series in Urdu/Hind

5. C# Floating-point Numeric Data types | Float, double & Decimal | C# Beginner Tutorial Series

How to Call one C# method from another C# script in Unity3d

Calling one method of a script from another script is common in Unity3d game development. In this Unity3d beginners tutorial I will show you how to call one c# method from another script.

How to add Serilog or Third Party Logging in Unity3d

In this video tutorial I have explained how to add third party logging system in Unity3d. This is advance logging way to log information in unity console with SeriLog. you can even write your games logs in specific text file with proper text formatting.

How to Import NuGet package in Unity3d

You often require to add third-party dll or nuget packages in Unity3d project. In this unity tutorial I will show you step by step how to add Nuget Package or dll into Unity3d project. For this tutorial we choose newtonsoft nuget package. You can adopt these steps for any nuGet package.

Here are the details,
      go to your desired NuGet package webpage.
      on the right side **Download Package** option click it.
      your package **.nupkg** file will be downloaded.
      change its extension to .zip and extract it
      go to lib and copy your package dll file from net or any netstandard folder. For [your unity project compatibility purposes][2] view this:

      open unity workspace and create plugin folder
      paste your dll file here.

Unity Webgl Issues and Solutions

During my extensive interaction with unity WebGL, I found different things that are difficult to handle in unity WebGL or Unity Webgl has some serious limitations (But nevertheless I have managed to stream large 3D area in unity WebGL with asset bundles). I have made this post in order to show you Unity3D WebGL issues sheet and if you are interested to see what technologies or toolchain Unity WebGL using behind the Scene then check this post. So, without a particular order here is the list of unity webgl limitations with relevant references for your further research. 



1. You cannot use Threads in unity WebGL. Here is the error that you will get when thread try to start:
SystemException: Thread creation failed.
UnityLoader.js:4   at System.Threading.Thread.StartInternal (System.Security.Principal.IPrincipal principal, System.Threading.StackCrawlMark& stackMark) [0x00000] in <00000000000000000000000000000000>:0
GameDev Question
Unity Forum
Unity Webgl Doc
Update: Unity claim that in Version 2019.1.0 they have added multiple Multithreading support but it was not working according to my test and now I also find this that there was bug with the problem which has fixed in Unity 2020.1.0 and Unity 2019.4.7 (untested)

2. If you are continuously pressing any keyboard input key and meanwhile you lost focus to WebGL canvas in the browser, the input will still work even after releasing the key. The situation may get worst in the Edge browser.
Ref:
SE Question
Maybe resolved in Unity 2019.3.0 but I have tested and still the same problem is happening.

Game Pause on error in Unity3d

For debugging purposes, you may require to pause the game on an error so that you can inspect the game situation. For this reason, you can follow these steps:

1. Write an error log in block of the code

    Debug.LogError("Exception occured");

And before running the editor open console and hit Error Pause in the console log.


The game will pause as any error occurred in the console.

  

How to send email form Unity3d and C# using gmail

Here are the 7 steps guide to send an email from your unity game using Gmail service. With gamil mail service you can send email in unity3d.

Steps for Gmail Account:

1. Login to Gmail Account
2. Go to at this location https://myaccount.google.com/security
3. Go to the Less secure app access section and Turn on Allow less secure app access (see image below)


Steps for Unity

4. Create a Unity project (or in your existing project) Make a script with SendEmail name and Copy Below code.
5. Attach the script with any game-object in your hierarchy.
6. Provide the credential in the inspector in the script (like your account and password and receiver account, message body, etc)
7. Run the game, it will send the email to the desired address in the start function

Note: If your system is behind a proxy then, email may not be sent and throw an exception.