- Home /
Remove particular objects from array
Hey everyone, I'm stuck for a while on the following: After a while I finally managed to get a working 'Path placing' system, the only problem is that I'm unable to remove the path (example: http://i.imgur.com/0xdL662.gif). Every 'tile' is passed in to an array called "GameArray".
The placement consists of three stages:
1) placing the first 'tile'.
2) after placing the first tile, it keeps on creating tiles until it's at the mouse position
3) left click on the current position will stop the creation.
I want the tiles to be destroyed if I move the cursor back. The struggle is: How do I only destroy the tiles above the cursors' position.
The tiles appear to be quads correct? If so, could you raycast and see if the ray collides with a quad and if it does, you remove that quad from the array? Also be careful not to erase the current tile directly after placing it, otherwise you won't be able to place any tiles.
Isn't it easier to remove the tiles (they are rectangular) which are above the cursors position? But how do I check whether the last object in an array is above the cursors position?
I have the following code to detect the cursors position:
float hitdist = 0.0f;
Plane PlayerPlane = new Plane (Vector3.up, Instance.transform.position);
Ray RayTest = Camera.main.ScreenPointToRay(Input.mousePosition);
if (PlayerPlane.Raycast (RayTest, out hitdist)){
Z$$anonymous$$ouse = RayTest.GetPoint(hitdist).z;
ZInstance = Instance.transform.position.z;