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

How much Unity ads pay per 1000 impression

Changing position of gameObjects in unity by C# script

Finding a GameObject by C# script in unity

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

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

GetComponent method in unity to access component by C# script

How to install unity editor

Activating and deactivating gameObjects in unity by C# script

Changing Image in unity by C# script