Unity project have damaged every time and I can`t run it in Editor (865003)

I am beginner in Unity and try to create my First Game.

Right now I try to write script that full my field by Hexs, that looks like this:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class HexManager : MonoBehaviour
{
    [SerializeField] private float _width, _height;
    [SerializeField] private float _Xstart, _Ystart, _Xstep, _Ystep, _shift;
    [SerializeField] private Hex _tilePrefab;
    [SerializeField] private Transform _cam;
    void Start()
    {
        GenerateGrid();
    }
    void GenerateGrid()
    {
        for (float y = _Ystart, i = 0; y > _Ystart - _height * _Ystep; y -= _Ystep, i++)
        {
            float shift = 0;
            if (i % 2 != 0) shift = _shift;
            for (float x = shift + _Xstart, j = 0; y < shift + _Xstart + _width * _Xstep; y += _Xstep, j++)
            {
                var spawnedTile = Instantiate(_tilePrefab, new Vector3(x, y), Quaternion.identity);
                spawnedTile.name = $"Hex {i} {j}";
            }
        }
    }
}

!(Screenshot 1 — Postimages]


!(Screenshot 2 — Postimages]
And every time, firstly my project closes, in few time. Then I try restart it and there is appeared message “it looks like another unity instance is running with this project open. Multiple Unity instances cant open the same project.”

After that I already can’t run my project, when I tap “Play” button, Editor just freeze and I can close it only with Task Manager. I’ve try to copy project, re-create it, but every time I bump into such error. And so about five times

Also I read on old forums that reason in Lockfile in Temp Folder, but I can’t to delete it. Of course I can every time backup my project, but it will be too tiresome, if create big project))


The Editor is freezing because there’s most likely something wrong with your code that causes it to go infinite. Unity will happily run code that goes on forever, causing it to hang and requiring you to force quit it.

I can’t say I know what’s going on in your code, but I would take another look at it.