@ivkoni yes you are right i dit it seperately, thanks for the explanation
another frind from ratking.de took a look in the script and now, if someone is interested in the working result:
using UnityEngine;
using System.Collections;
public class VirusSpawner: MonoBehaviour
{
public int x;
public int y;
public Vector3 target;
GameObject[,] myArray = new GameObject[10,10];
public GameObject cursor;
public GameObject good;
public GameObject bad;
public GameObject showit; // für debug um array inhalte anzuzeigen
void Update ()
{
RaycastHit hit;
if (Physics.Raycast(camera.ScreenPointToRay(Input.mousePosition), out hit))
{
target.x = Mathf.Round(hit.point.x + hit.normal.x * 0.5f ) ; // die Position über:
target.y = Mathf.Round(hit.point.y + hit.normal.y * 0.5f ) ; // von Camera durch Zeigerposition
target.z = Mathf.Round(hit.point.z + hit.normal.z * 0.5f ) ; // und wird aufgerundet
x = (int)target.x;
y = (int)target.z;
if (hit.collider.name == "BuildGround" Input.GetMouseButtonDown(0))
{
Destroy(myArray[x, y]); //das löscht das alte tile
myArray[x, y] = CreateTile (x, y, good);
}
if (hit.collider.name == "BuildGround" Input.GetMouseButtonDown(1))
{
Destroy(myArray[x, y]);
myArray[x, y] = CreateTile (x, y, bad);
}
if (hit.collider.name == "BuildGround" Input.GetMouseButtonDown(2))
{
Destroy(myArray[x, y]);
myArray[x, y] = null; // auf null setzen, sonst ist das missing
}
}
cursor.transform.position = target; // die cursor Ziel-Vorschau
showit = myArray[x,y]; // debug, verbessern das wird die ganze zeit berechnet
}
//warum ist diese Funktion ein gameobject ? den Teil hab ich von Dir
private GameObject CreateTile (int i, int j, GameObject tile) // und demensprechend werden Tiles 0-11 gespawnt
{ //fals hier schon ein Teil ist muß es vorher gelöscht werden
//decalPrefab = good;
GameObject go = (GameObject)Instantiate(tile, new Vector3(i , 0.5F, j), Quaternion.identity);
Tile t = go.AddComponent<Tile>(); //wohin wird das als Componente hinzugefügt
t.x = i;
t.y = j;
return go;
}
}
Now you can place 2 difrerent objects with the LMB and RMB. They get stored in the array :razz:
Erase them with MMB