Extension method must be defined in a non-generic class

The script :

using UnityEngine;

public class HexCell : MonoBehaviour {

    public HexCoordinates coordinates;

    public Color color;

    [SerializeField]
    HexCell[] neighbors;

    public static HexDirection Opposite (this HexDirection direction)
    {
        return (int)direction < 3 ? (direction + 3) : (direction - 3);
    }



    public HexCell GetNeighbor (HexDirection direction)
    {
        return neighbors[(int)direction];
    }

    public void SetNeighbor(HexDirection direction, HexCell cell)
    {
        neighbors[(int)direction] = cell;
        cell.neighbors[(int)direction.Opposite()] = this;
    }


}

So I was following a CatLikeCoding tutorial, and when I finished with the second part of the tutorial, I go to Unity and I see an error in the console.
(3, 14): error CS1106: Extension method must be defined in a non-generic class.

Here’s the tutorial -

So that error likely does not pertain to that snippet of code since it’s referring to extension methods in a generic class.

Looking at the tutorial there is 3 extension methods:
HexDirection Next(this HexDirection direction)
HexDirection Previous(this HexDirection direction)
HexDirection Opposite(this HexDirection direction)

Where did you define these methods? Show us that source? It’s likely been defined in a generic class which C# does not support.

[edit]
sorry, no, it is this snippet. I just noticed you did define Opposite here (sorry just woke up).

That method ‘Opposite’ can’t be in this class… extension methods need to be in a static class.

Do something like this:

public static class HexDirectionExtensions
{

    public static HexDirection Opposite (this HexDirection direction)
    {
        return (int)direction < 3 ? (direction + 3) : (direction - 3);
    }
}

Which looking at the tutorial is what it tells you to do.

Then what would the issue be?

I edited my post with an explanation.

Also here is where the tutorial explains how you should have done it:

sorry, i didn’t notice it. thank you.

I probably hadn’t finished the edit when you saw it.

But yeah, hopefully that gets you moving again. Good luck!

it appears that downloading the provided package fixed it.