Variables in C# script in unity

There are many variables in unity some of them are usual as we use and some are created by unity API

common variables are

int - all you to store integer value.

float - to store float value

bool - give only true or false value

string -  can store string value

other variable are

GameObject - it is used for accessing gameObject of unity

AudioSource  - using audioSource as a variable

Camera - use camera as a variable

Using variables in Script

you can define variables as
<variable> <name>

defining variables in unity script

Like in above image i have define a public variable of type String that can store string value.
if variable is public then it can be access by other script and value can be change in inspector.
if nothing public or private is not written then it will be private variable.

You can change variable value in inspector after attaching to a gameObject

When you create a script in unity it will work as a component and as you attach it to a gameObject it will show you all public variables can be edited in inspector

Popular posts from this blog

How to fix Android Gradle Build failed error in unity

Changing position of gameObjects in unity by C# script

WaitForSeconds and coroutine in unity | delaying a code action for some time in C#

Unity ads install error from package manager

SerializeField and HideInInspector in unity in C# script

playing audio in unity by C# script

GetComponent method in unity to access component by C# script

how to setup unity ads in mobile game

How to install unity editor