classes, namespaces and declaring variables in C# for Unity

Karuna Ketan
1 min readDec 1, 2022

Day1:

I learned about classes, namespaces and declaring variables…

1st Program:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Test : MonoBehaviour

{

Rigidbody2D _rb;

float _walkspeed;
float _inputHorizontal;

// Start is called before the first frame update
void Start()
{
_rb = gameObject.GetComponent<Rigidbody2D>();

_walkspeed = 5.5f;
}

// Update is called once per frame
void Update()
{
_inputHorizontal = Input.GetAxisRaw("Horizontal");

if(_inputHorizontal != 0)
{
_rb.AddForce(new Vector2(_inputHorizontal * _walkspeed, 0f));
}
}
}

From above program:

System.Collections;
System.Collections.Generic;
UnityEngine;
  • These are called namespaces. Simply namespace is the collection of classes… We can say them library also…
public class Test : MonoBehaviour
  • MonoBehaviour is the class which is inside the namespace named UnityEngine and now we can access void Start() and void Update() which is also simply the syntax of class MonoBehaviour…

click here to follow me in LinkedIn for more updates…

click here to follow me in GitHub for more updates…

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Karuna Ketan
Karuna Ketan

Written by Karuna Ketan

Game Designer and Developer | Unity, Unreal Engine, Blender

No responses yet

Write a response