---
title: "Variables and Functions"
content_type: tutorial
url: "https://learn.unity.com/tutorial/variables-and-functions?language=en"
language: en
difficulty: beginner
duration_minutes: 10
unity_version:
  - "2021.3"
supported_unity_versions:
  - name: "2021.3"
    url: "https://learn.unity.com/tutorial/variables-and-functions.md?language=en&version=2021.3"
available_languages:
  - name: "en"
    url: "https://learn.unity.com/tutorial/variables-and-functions.md?language=en"
  - name: "es"
    url: "https://learn.unity.com/tutorial/variables-and-functions-1.md?language=es"
  - name: "ja"
    url: "https://learn.unity.com/tutorial/bian-shu-toguan-shu-nitsuite.md?language=ja"
  - name: "ko"
    url: "https://learn.unity.com/tutorial/byeonsu-mic-hamsu.md?language=ko"
  - name: "zh-cn"
    url: "https://learn.unity.com/tutorial/bian-liang-he-han-shu.md?language=zh-cn"
last_updated: "2026-10-07T22:05:18.000Z"
---

# Variables and Functions

Learn what variables and functions are in C# and how they store and process data in your Unity scripts.

What are Variables and Functions, and how do they store and process information for us?

Previous: [Scripts as Behavior Components](https://learn.unity.com/tutorial/scripts-as-behaviour-components?projectId=5c8920b4edbc2a113b6bc26a)

Next: [Conventions and Syntax](https://learn.unity.com/tutorial/conventions-and-syntax?projectId=5c8920b4edbc2a113b6bc26a)

## 1. Variables and Functions

[Video](https://connect-mediagw.unity.com/h1/20220104/videos/9d3b1cb9-cee0-4ac0-b71d-cfea2f6f35cf_U_Beginner_2_VariablesandFunctions.mp4) ([Transcript (en)](https://connect-mediagw.unity.com/h1/20220104/c3e0f55f-a3fc-4180-aab5-96b5a2701877_B_02_Variables_And_Functions_v5.0.vtt))

```csharp
using UnityEngine;
using System.Collections;

public class VariablesAndFunctions : MonoBehaviour
{   
    int myInt = 5;
    
    
    void Start ()
    {
        myInt = MultiplyByTwo(myInt);
        Debug.Log (myInt);
    }
    
    
    int MultiplyByTwo (int number)
    {
        int result;
        result = number * 2;
        return result;
    }
}
```
