The hot fix that has us extend the collider does not work for me because the colliders in other lanes are starting to touch and causing problems like the attacker above a defender attacking them, here are some pictures I show my code in it as well but here is my code pasted out, let me know what else you need!
Here I show how it currently snaps:
This shows that they are still overlapping, and the box collider is already pushing into the next row, yet I can still do this: ![Screenshot (14)|690x388] (upload://7JpodJr1bofdKHCqGYzMnJnYAcr.jpeg) It may be bad quality, but the box collider on the mole is shown:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SpawnDefenders : MonoBehaviour
{
Defender defender;
private void OnMouseDown()
{
AttemptToPlaceDefender(GetSquareClicked());
}
private Vector2 GetSquareClicked()
{
Vector2 clickPos = new Vector2(Input.mousePosition.x, Input.mousePosition.y);
Vector2 worldPos = Camera.main.ScreenToWorldPoint(clickPos);
Vector2 gridPos = SnapToGrid(worldPos);
return gridPos;
}
public void SetSelecDefender(Defender defender2Select)
{
defender = defender2Select;
}
private void AttemptToPlaceDefender(Vector2 gridPos)
{
var MushDisplay = FindObjectOfType<MushDisplay>();
int defenderCost = defender.MushCost();
//if we have enough money, then spawn defender and remove munny
if (MushDisplay.HasMush(defenderCost))
{
SpawnDefender(gridPos);
MushDisplay.MinMush(defenderCost);
}
}
private Vector2 SnapToGrid(Vector2 rawWorldPos)
{
float newx = Mathf.RoundToInt(rawWorldPos.x);
float newy = Mathf.RoundToInt(rawWorldPos.y) ;
return new Vector2(newx, newy);
}
private void SpawnDefender(Vector2 roundedPos)
{
Defender newDefender = Instantiate(defender, roundedPos, Quaternion.identity) as Defender;
Debug.Log(roundedPos);
}
}
Edit: Spelling and some context to screenshots
Fixed, see my post below for how I finally got it working after someone pointed out my error!