Skip to main content
Unity3D

Introduction to C# in Unity3D #2: Scripts! Scripts! Scripts! 📑

By January 25, 2021February 11th, 2021No Comments
Unity3D C# Scripts
Unity3D C# Script Basics
Unity3D Scripts
https://www.youtube.com/watch?v=QUyLpiRDjHs&feature=youtu.be
📑 In Unity3D you will hear the word script a lot!'
📑To create a script: Assets < C# < Script or Right click in the Assets folder < Create and < C# Script
📑 Script names should be in Pascal case. PascalCase is a naming convention in which the first letter of each word in a compound word is capitalized. For example:
Unity3d Script Basics
📑Script names should NOT contain any C# keywords (int, string, null etc). Also do not use special characters for example *, %, $. You can use _ though
📑Scripts are considered behavioral components as they add some "behavior"/function to your game objects
📑 Scripts will not execute till you attach them to a game object and press play. Scripts are components that have to be added to game objects
//using imports a namespace
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CubeController : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()

    // Update is called once per frame
    void Update()
    {

    }
}

📑 Namespaces are included at the top of the script. Namespaces are container of the classes, events, delegates etc. For example UnityEngine namespace allows us to use all the classes, events, delegates etc that belong to it.

📑 classes are like containers for variables and functions pertaining to a game object to which the script is attached. Classes manage a game objects behavior/function. So classes group a game objects properties and behavior together

📑 The class name is the same as the file name

📑 The MonoBehaviour class is the base class for your Unity3D script and this is added by the UnityEngine namespace. MonoBehaviour is a class in namespace UnityEngine.

📑 Start() and Update() event methods are part of the MonoBehaviour classes and added by default whenever you make a new script

Leave a Reply