7. Types

Type system

Typeof

Type casting

C# Docs: Casting and type conversions

Generics

C# Fundamentals: Generic classes and methods

GetComponent<Rigidbody>();

Special types

Enums

public class EnumScript : MonoBehaviour 
{
    enum Direction {North, East, South, West};

    void Start () 
    {
        Direction myDirection;
        myDirection = Direction.North;
    }
    
    Direction ReverseDirection (Direction dir)
    {
        if(dir == Direction.North)
            dir = Direction.South;
        else if(dir == Direction.South)
            dir = Direction.North;
        else if(dir == Direction.East)
            dir = Direction.West;
        else if(dir == Direction.West)
            dir = Direction.East;
        return dir;     
    }
}

Create your own type

xx

Structs

xx