Im trying to snap an object in my scene to an plane, the objects is being dragged by the camera + mouse. The problem is, it does not snap to the Plane. And i guess this is because i have no grid script attached to my plane.
This is the code that is attached to the Main Camera:
using UnityEngine;
using System.Collections;
public class TileHandler : MonoBehaviour {
public GameObject EditorPrefab;
public Vector3 GridSize;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
Vector3 MouseWorld = GetComponent<Camera>().ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, -GetComponent<Camera>().transform.position.z - 5.0f));
if (Input.GetKey(KeyCode.LeftControl))
{
EditorPrefab.transform.position = new Vector3(((int)(MouseWorld.x / GridSize.x)) * GridSize.x, ((int)(MouseWorld.y / GridSize.y)) * GridSize.y, -5.0f);
}
else
{
EditorPrefab.transform.position = MouseWorld;
}
}
}
As you can see here:
![]()
Any help is appreciated!
Thanks!