- Home /
CS0246: The type or namespace name `DateTime' could not be found.
I'm trying to make it so that you get a life for every real life minute you are playing my game (not while offline). I have this script in C# but Im getting an error saying:
error CS0246: The type or namespace name `DateTime' could not be found. Are you missing a using directive or an assembly reference?
The script I have is this:
DateTime oldDate; //the time that the game started
DateTime currentDate; //the time since the start of the game
int minutes; //the time passed in minutes
int livesGiven;
void Start()
{
minutes = 0; //the number of minutes we have been on is 0
oldDate = System.DateTime.Now; //the oldDate is the time at the start of the game
}
void Update()
{
currentDate = System.DateTime.Now; //the current time is now
minutes = currentDate.Minute - oldDate.Minute; //the number of minutes passed is equal to the time right now minus the time the game was started
if(minutes > livesGiven) //if a minute has passed
{
Lives++; //add a life
livesGiven++; //add 1 to the number of lives given
}
This is just part of the code I do have a lives system and everything but the only errors I am getting are with 'DateTime'
Answer by rutter · Aug 21, 2014 at 09:15 PM
You need to either include the appropriate namespace or use a fully qualified class name every time you mention DateTime.
In particular, your variable declarations up top don't use a fully qualified name.
Like this:
System.DateTime oldDate;
System.DateTime currentDate;
Your answer
Follow this Question
Related Questions
CSharpMsgrExtended: CS0246: The type or namespace name `Exception' could not be found. 2 Answers
Photon and the tutorial on cjrgaming.com 1 Answer
[Win app] CS0246 & CS0234 :BindingFlags and Cryptography 2 Answers
Missing assembly references when importing/upgrading DOTS stack 1 Answer
Why not Boo? 1 Answer