Script not running from GameObject

New guy to c# / Super basic setup

One Cube
One Camera
One Script => NewScript

Script is attached to cube (I see it in the Inspector window when I select Cube)

No errors, everything compiles fine, here’s the script:

using UnityEngine;
using System.Collections;

class NewScript : MonoBehaviour
{

public int bank = 1000;
	
void Test()
	{
		bank = bank -100;
		print(bank);
		print(100);
		Debug.Log (bank);
		Debug.Log(100);
	}

}

Yet nothing goes to the console when I hit play…

From what I understand, dropping a script on a GameObject and hitting play should do something but it seems to never get called?

Thanks!

You never run the Test function. Functions must be called from somewhere to execute, with the exceptions being some MonoBehaviours such as Awake, Start, Update, etc.

–Eric

Thanks!

I’ve added a function that calls test within the class and it works now…

I can’t do anything outside a class it seems though, it’s always giving errors about “namespace” whenever i try to put something outside the CLASS’s brackets?

Is that normal? I find it kinda odd, I though simply typing Test(); should have called it no?

All code should be inside a class, and inside a function (aside from declaring variables, which can be outside functions but must be inside a class).

–Eric