Yup, same issue again, though it’s showing up on VSC this time at least. I’m a few minutes into the Move Action Validate video.
Error is:
“GridPosition’ does not contain a definition for ‘IsValidGridPosition’ and no accessible extension method ‘IsValidGridPosition’ accepting a first argument of type ‘GridPosition’ could be found (are you missing a using directive or an assembly reference?”
Again, I’m sure I have a perfect copy of the code from the course, but I’ll copy it below incase:
LevelGrid script (where the error is located):
public class LevelGrid : MonoBehaviour
{
public static LevelGrid Instance {get; private set;}
[SerializeField] private Transform gridDebugObjectPrefab;
private GridSystem gridSystem;
private void Awake()
{
if (Instance != null)
{
Debug.LogError("There's more than one LevelGrid! " + transform + " - " + Instance);
Destroy(gameObject);
return;
}
Instance = this;
gridSystem = new GridSystem(10, 10, 2f);
gridSystem.CreateDebugObjects(gridDebugObjectPrefab);
}
public void AddUnitAtGridPosition(GridPosition gridPosition, Unit unit)
{
GridObject gridObject = gridSystem.GetGridObject(gridPosition);
gridObject.AddUnit(unit);
}
public List<Unit> GetUnitListAtGridPosition(GridPosition gridPosition)
{
GridObject gridObject = gridSystem.GetGridObject(gridPosition);
return gridObject.GetUnitList();
}
public void RemoveUnitAtGridPosition(GridPosition gridPosition, Unit unit)
{
GridObject gridObject = gridSystem.GetGridObject(gridPosition);
gridObject.RemoveUnit(unit);
}
public void UnitMovedGridPosition(Unit unit, GridPosition fromGridPosition, GridPosition toGridPosition)
{
RemoveUnitAtGridPosition(fromGridPosition, unit);
AddUnitAtGridPosition(toGridPosition, unit);
}
public GridPosition GetGridPosition(Vector3 worldPosition) => gridSystem.GetGridPosition(worldPosition);
public bool IsValidGridPosition(GridPosition gridPosition) => gridPosition.IsValidGridPosition(gridPosition); \\\ Error here
}
Testing script:
public class Testing : MonoBehaviour
{
[SerializeField] private Unit unit;
private void Start()
{
}
private void Update()
{
if (Input.GetKeyDown(KeyCode.T))
{
unit.GetMoveAction().GetValidActionGridPositionList();
}
}
}
GridPosition script:
public struct GridPosition : IEquatable<GridPosition>
{
public int x;
public int z;
public GridPosition(int x, int z)
{
this.x = x;
this.z = z;
}
public override bool Equals(object obj)
{
return obj is GridPosition position &&
x == position.x &&
z == position.z;
}
public bool Equals(GridPosition other)
{
return this == other;
}
public override int GetHashCode()
{
return HashCode.Combine(x, z);
}
public override string ToString()
{
return $"x: {x}; z: {z}";
}
public static bool operator ==(GridPosition a, GridPosition b)
{
return a.x == b.x && a.z == b.z;
}
public static bool operator !=(GridPosition a, GridPosition b)
{
return !(a == b);
}
public static GridPosition operator +(GridPosition a, GridPosition b)
{
return new GridPosition(a.x + b.x, a.z + b.z);
}
public static GridPosition operator -(GridPosition a, GridPosition b)
{
return new GridPosition(a.x - b.x, a.z - b.z);
}
}
Have been through everything three times getting increasingly frustrated and can’t see anything wrong with any of the scripts.
If this is a problem with Unity or VSC, how do I identify it and fix it?