---
title: "Variables and Functions"
content_type: tutorial
url: "https://learn.unity.com/course/beginner-scripting-old/unit/beginner-scripting/tutorial/variables-and-functions?language=en"
language: en
container_type: course
container_title: "Beginner Scripting"
container_url: "https://learn.unity.com/course/beginner-scripting-old.md?language=en"
unit_title: "Beginner Scripting"
unit_url: "https://learn.unity.com/course/beginner-scripting-old/unit/beginner-scripting?language=en"
standalone_markdown_url: "https://learn.unity.com/tutorial/variables-and-functions.md?language=en"
previous_title: "Scripts as Behaviour Components"
previous_url: "https://learn.unity.com/course/beginner-scripting-old/unit/beginner-scripting/tutorial/scripts-as-behaviour-components?language=en"
previous_markdown_url: "https://learn.unity.com/course/beginner-scripting-old/unit/beginner-scripting/tutorial/scripts-as-behaviour-components.md?language=en"
next_title: "Conventions and Syntax"
next_url: "https://learn.unity.com/course/beginner-scripting-old/unit/beginner-scripting/tutorial/conventions-and-syntax?language=en"
next_markdown_url: "https://learn.unity.com/course/beginner-scripting-old/unit/beginner-scripting/tutorial/conventions-and-syntax.md?language=en"
difficulty: beginner
duration_minutes: 10
unity_version:
  - "2019.3"
  - "2019.2"
  - "2019.1"
  - "2018.4"
  - "2018.3"
  - "2018.2"
  - "2018.1"
  - "2017.4"
  - "2017.3"
  - "2017.2"
  - "2017.1"
  - "5.x"
  - "4.x"
supported_unity_versions:
  - name: "2019.3"
    url: "https://learn.unity.com/tutorial/variables-and-functions.md?language=en&version=2019.3"
  - name: "2019.2"
    url: "https://learn.unity.com/tutorial/variables-and-functions.md?language=en&version=2019.2"
  - name: "2019.1"
    url: "https://learn.unity.com/tutorial/variables-and-functions.md?language=en&version=2019.1"
  - name: "2018.4"
    url: "https://learn.unity.com/tutorial/variables-and-functions.md?language=en&version=2018.4"
  - name: "2018.3"
    url: "https://learn.unity.com/tutorial/variables-and-functions.md?language=en&version=2018.3"
  - name: "2018.2"
    url: "https://learn.unity.com/tutorial/variables-and-functions.md?language=en&version=2018.2"
  - name: "2018.1"
    url: "https://learn.unity.com/tutorial/variables-and-functions.md?language=en&version=2018.1"
  - name: "2017.4"
    url: "https://learn.unity.com/tutorial/variables-and-functions.md?language=en&version=2017.4"
  - name: "2017.3"
    url: "https://learn.unity.com/tutorial/variables-and-functions.md?language=en&version=2017.3"
  - name: "2017.2"
    url: "https://learn.unity.com/tutorial/variables-and-functions.md?language=en&version=2017.2"
  - name: "2017.1"
    url: "https://learn.unity.com/tutorial/variables-and-functions.md?language=en&version=2017.1"
  - name: "5.x"
    url: "https://learn.unity.com/tutorial/variables-and-functions.md?language=en&version=5.x"
  - name: "4.x"
    url: "https://learn.unity.com/tutorial/variables-and-functions.md?language=en&version=4.x"
last_updated: "2026-09-30T20:33:20.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;
    }
}
```
