Showing posts from July, 2021

how do I access variable or call a function from other script in unity

 Accessing and modifying variable and calling from other script is quit simple. So in this post we access variable from other script and modify and call it. so lets get started.  Lets create an empty scene in your project. In this scene create two empty game object and named them "variable and function script" and "test  script". Now create two scripts one in which we declare variable and function named as "variable_function" and second by which we access these variable and call function named as "test".  Drag and drop variable_function script in "variable and function script" gameObject and test script in "test script" gameObject. You can use any name of gameObject and script these names are just for reference so you can understand which gameObject and scripts I am talking about. variable_function script using   System . Collections ; using   System . Collections . Generic ; using   UnityEngine ; public   class   variable_fun

how to pause game by script in unity ( with android back button or with computer esc key )

In this post we will create a simple ui button to pause game and show paused UI and other button to resume game so let's get started. Create a Button UI gameObject and named as pause button. (you can name whatever you want).change its text component to pause. if you want to show a (  ||    )  icon to pause game then delete text child object of pause button and then drag your icon in source image of Image component in inspection window. Then create a Panel UI GameObject named as pause menu UI and create a child text ui gameObject (write paused it it text value and place it at top of pause menu panel) and one child button UI gameObject placed in the middle of pause menu panel and named as resume(Change button to resume). Make sure both text and button are child of pause menu UI. this is a simplest UI. You can design your own according to your need. You can add many UI buttons , UI Image, and text in pause menu ui panel and design in your own way like replay, get free coins, home and

Creating count down timer in unity by c# script

 In many cases in game we have to show count down timer. in this post i will explain how to create a timer which show a timer 3... 2.... 1.....  . so first create a simple basic gameObjects :- 1. Create a new scene in your unity project. 2. Create a UI text GameObject in your scene. as I have created and named as "timer text". and set text size, position, font, color of text etc according to you need. 3. Create a new C# script. I named it as "timer". always take care that your C# script name and class name should be same. 4. Create an other empty GameObject. I named it as "timer script". and attach C# timer script with it. 5. Now open timer C# script. Add UnityEngine.UI namespace so that we can use UI component and declare a text and float of name "timer_txt" and "t". You can use any name whatever you want. I just wrote these names so that you can understand which name i have used. 6.drag and drop timer text ui gameObject into it.   the

How to change UI image by c# script in unity with example

Changing a UI image with script in runtime is a quit simple thing. in many case you want to change UI image at runtime so Lets understand it by a simple example. 1. first we need a UI Image GameObject so create a UI Image Object by navigating GameObject > UI > Image or whatever steps you want to create, just create. 2. then create a c# script. and attach it any gameobject you want. replace a UI image you need refence UI image so declare a Image of name whatever you want and declare sprite for changed sprite reference. I have named Image as original_img and sprite to change as other_img. 4.Drag Image gameObject from hierarchy window to attacched script Image (named original_img) and also drag image sprite from assets folder to script sprite (named as other_img).  4. lets create a change_image() function. you can use this function or inside code to change image where you want. As we have used in start method. using   System . Collections ; using   System . Collections . Generi

Difference between unity personal and unity plus/pro/enterprise

 Unity is a great tool to create games for different platform with single code. Unity have paid and free version. Unity personal If you are a hobbyist or have low financial condition then unity personal is for you. It is completely free for creating games and you can earn money with it but it have only one condition that your organization (you) should not have earned more then $100k in last 12 months which is quit high.  Features of unity personal Core unity engine for game development all editor versions including beta versions. all platform build support. Bolt visual scripting You can use unity ads and unity in app purchase in your game limitation of unity personal organization revenue should not greater then $100k in last 12 months (including funding and other sources) Unity branding in splash screen. Don't have source code access. Unity subscriptions If your revenue or funding greater then $100k  in last 12 months then you have purchase a subscription. Unity offer three differe