Well, I don’t remember having change this script in this lesson.
I join you the actual code of my GridPosition Script.
using System;
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)
{
throw new NotImplementedException();
}
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)//Création de la méthode pour autoriser les additions de grid position dans le script MoveAction ligne 65.
{
return new GridPosition(a.x + b.x, a.z + b.z);
}
public static GridPosition operator -(GridPosition a, GridPosition b)//Création de la méthode pour autoriser les soustarctions de grid position dans le script MoveAction ligne 65.
{
return new GridPosition(a.x - b.x, a.z - b.z);
}
}