- Katılım
- 5 Mart 2014
- Mesajlar
- 5.701
- Makaleler
- 12
- Çözümler
- 44
C#:
Ray SendLight = GameObject.Find("Kamera").GetComponent<Camera>().ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(SendLight, out Block, 3))
{
Vector3 BuildPos = Block.point;
var PosX = Mathf.Round(BuildPos.x);
var PosY = Mathf.Round(BuildPos.y);
var PosZ = Mathf.Round(BuildPos.z);
var BlockExists = false;
GameObject[] GrassBlocks = GameObject.FindGameObjectsWithTag("Grass");
foreach (var item in GrassBlocks)
{
if (PosX == item.transform.position.x & PosY == item.transform.position.y & PosZ == item.transform.position.z)
{
BlockExists = true;
}
}
if (!BlockExists)
{
GameObject Obj = Instantiate(Grass, transform.position, transform.rotation);
Obj.transform.rotation = new Quaternion(0, 0, 0, 0);
Obj.transform.position = new Vector3(PosX, PosY, PosZ);
}
}
Bu kod ile farede sağ tıklayınca blok ekliyor. Bazı pozisyonlarda blok eklenirken bazılarında bloğun içine ekleniyor. Kodun neyi eksik?
Çözüm
"Grass" bloğunun collider seviyesi "1,01" olarak ayarlanınca çözüldü.
Son düzenleme: