Hello, I am trying to build an RCT, Prisonarchitect or Sim like game in Unity2D.
The idea is that I press a UI button, get a tile that follows the mouse and by pressing the mouse button a clone of that tile spawns at the mouse(x;y) location.
This should not be a problem since this is pretty much basic.
But When I try to place a single tile I get a ton of tiles in the same place. Somehow I need way to scan for an already existing tile (or other game_object) that is already placed at that location.
I have tried it with “Tags” but I could not get to work. My script so far is also for unity3D I have tried to modify it so that it don’t need the Vector3 component but it did not work either.
I have no idea. I am desperate right now. The solution can’t be that difficult but I am not able to see it.
-Thanks
var depth = 10.0;
var FloorPrefab : Transform;
function Update ()
{
//Follow mouse
var mousePos = Input.mousePosition;
var wantedPos = Camera.main.ScreenToWorldPoint (Vector3 (mousePos.x, mousePos.y, depth));
transform.position = wantedPos;
{
//Spawn object at mouse position
var mousex = Input.mousePosition.x;
var mousey = Input.mousePosition.y;
var ray = camera.main.ScreenPointToRay (Vector3(mousex,mousey,0));
var hit : RaycastHit;
}
if ( Input.GetMouseButtonDown(1) )
{
Destroy(gameObject);
}
if (Physics.Raycast (ray, hit, 200))
{
if ( Input.GetMouseButtonUp(0) )
{
var create = Instantiate(FloorPrefab, hit.point, Quaternion.identity);
}
}
}