I thought I had done something with my script that was causing the blocks not to snap. I didn’t realize he was using snap settings and ctrl to move things in the environment.
2 Likes
I had forgotten about snap settings! Initially, I was wondering if I needed to add the cubeEditor script to the enemy blocks. Thanks for mentioning this.
1 Like
Hi All,
I am not a big fan of holding down CTRL when snapping, I find that I forget and things get messy and frustrating. Instead I made a basic little script based on the cube editor script and attached it to non-friendly blocks. Below is the code I used.
I hope this might help.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[SelectionBase]
[ExecuteInEditMode]
public class CubeEditorNonPlay : MonoBehaviour
{
const int gridSize = 10;
void Update()
{
PostionSnap();
}
private void PostionSnap()
{
Vector2Int gridPos = new Vector2Int
(Mathf.RoundToInt(transform.position.x / gridSize),
Mathf.RoundToInt(transform.position.z / gridSize));
transform.position = new Vector3(gridPos.x * gridSize, 0f, gridPos.y * gridSize);
}
}
2 Likes