using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EditorMenuInputManager : MonoBehaviour {
public GameObject BasicBuildingBlockTransparent;
public GameObject BasicBuildingBlockSingle;
public List<GameObject> ShipBlockList = new List<GameObject>();
// Update is called once per frame
void Update () {
/*Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray))
{
Vector3 point = ray.GetPoint(1);
point.y = 0;
BasicBuildingBlock.transform.position = point;
}*/
var worldPoint = Camera.main.ScreenToWorldPoint(Input.mousePosition);
worldPoint.x = (int)worldPoint.x + (int)(worldPoint.y);
worldPoint.z = (int)worldPoint.z + (int)(worldPoint.y);
worldPoint.y = 0;
//var v = new Vector3(Input.mousePosition.x, Input.mousePosition.y, Input.mousePosition.z);
//var worldPoint = Camera.main.ScreenToWorldPoint(v);
//(int) faster then convert.toint32 required to snap position...
//worldPoint.x = (int)worldPoint.x;
//worldPoint.y = 0;
//worldPoint.z = (int)worldPoint.z;
BasicBuildingBlockTransparent.transform.position = worldPoint;
if (Input.GetMouseButtonUp(0))
{
ShipBlockList.Add(Instantiate(BasicBuildingBlockSingle));
ShipBlockList[ShipBlockList.Count - 1].name = (ShipBlockList.Count - 1).ToString();
ShipBlockList[ShipBlockList.Count - 1].transform.position = BasicBuildingBlockTransparent.transform.position;
}
}
}
So far This is what I’ve come up with my math for y is incorrect though.
When you move towards the top of the screen there is a gap between the object and where it is located and it gets bigger the further up the screen you go with the mouse. This does appear to be completely a math problem. I don’t know how to calculate y from the mouse correctly due to the isometric view.