C# Code Help
trying to make a tetris clone game and I keep on getting this error
CS0246 The type or namespace name 'Game' could not be found (are you missing a using directive or an assembly reference?)
9 Replies
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Tetromino : MonoBehaviour
{
float fall = 0;
public float fallsSpeed = 1;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
CheckUserInput();
}
void CheckUserInput()
{
if (Input.GetKey(KeyCode.RightArrow))
{
transform.position += new Vector3(1, 0, 0);
if (!CheckIsValidPosition())
{
transform.position += new Vector3(-1, 0, 0);
}
}
else if (Input.GetKey(KeyCode.LeftArrow))
{
transform.position += new Vector3(-1, 0, 0);
if (!CheckIsValidPosition())
{
transform.position += new Vector3(1, 0, 0);
}
}
else if (Input.GetKeyDown(KeyCode.UpArrow))
{
// Try rotating
transform.Rotate(0, 0, 90);
// Check if the new position is valid
if (!CheckIsValidPosition())
{
// If not, rotate back
transform.Rotate(0, 0, -90);
}
}
else if (Input.GetKeyDown(KeyCode.DownArrow) || Mathf.Round(Time.time) - fall >= fallsSpeed)
{
transform.position += new Vector3(0, -1, 0);
if (!CheckIsValidPosition())
{
transform.position += new Vector3(0, 1, 0);
}
fall = Mathf.Round(Time.time);
}
}
bool CheckIsValidPosition()
{
foreach (Transform mino in transform)
{
Vector2 pos = FindObjectOfType<Game>().Round(mino.position);
if (!FindObjectOfType<Game>().CheckInsideGrid(pos))
{
return false;
}
}
return true;
}
}
thats the code
the error message is fairly clear. You're referencing the name
Game
, specifically in the CheckIsValidPosition
method, but the compiler doesn't know what Game
you are referring to.doesn't look like you defined a class called
Game
You need to either add a
using
to reference an existing type Game
, or create a class called Game
.thanks I will try to do that
Also, in discord you can use the
key to denote that something is a code snippet
Like this
.
You can even use a code block (three of the
key at the top and bottom of your code) to make your code look like this:
thanks
$code
To post C# code type the following:
```cs
// code here
```
Get an example by typing
$codegif
in chat
For longer snippets, use: https://paste.mod.gg/