DataTypes

Tutorial

·

Beginner

·

+10XP

·

5 mins

·

(1851)

Unity Technologies

DataTypes

Learn the important differences between Value and Reference data types, in order to better understand how variables work.

This tutorial is included in the Beginner Scripting project.

Previous: Delta Time

Next: Classes

1. Data Types

DatatypeScript

using UnityEngine;
using System.Collections;

public class DatatypeScript : MonoBehaviour 
{
    void Start () 
    {
        //Value type variable
        Vector3 pos = transform.position;
        pos = new Vector3(0, 2, 0);
        
        //Reference type variable
        Transform tran = transform;
        tran.position = new Vector3(0, 2, 0);
    }
}

Complete this tutorial