public void OnEndDrag(PointerEventData eventData) { canvasGroup.alpha = 1f; canvasGroup.blocksRaycasts = true; rectTransform.anchoredPosition = slot.GetComponent <RectTransform>().anchoredPosition; Vector3 mousePos = Input.mousePosition; Ray ray = Camera.main.ScreenPointToRay(mousePos); RaycastHit hit; if (Physics.Raycast(ray, out hit, 1000f, layer)) { Vector3 worldPos = hit.point; if (itemToSpawn.GetComponent <Monkey>()) { AnimalFactory.CreateMonkey(5, 10, 50, worldPos, itemToSpawn.GetComponent <Monkey>().sex); GuideEventObserver.Instance.FirstAnimalSpawn(); } else { if (itemToSpawn.GetComponent <Hawk>()) { AnimalFactory.CreateHawk(3, 100, 200, 2, new Vector3(worldPos.x, worldPos.y + 5f, worldPos.z), itemToSpawn.GetComponent <Hawk>().sex); GuideEventObserver.Instance.FirstAnimalSpawn(); } else { Instantiate(itemToSpawn, worldPos, Quaternion.identity); } } } }
private void SpawnAnimals() { Vector3 randomPos; int randomIndex; int monkeyCount = 0; int hawkCount = 0; for (int k = 0; k < biome.animals.Length; k++) { for (int i = 0; i < VoxelData.worldSizeInChunks; i++) { for (int j = 0; j < VoxelData.worldSizeInChunks; j++) { randomIndex = chunks[i, j].voxelPositions.Count - Random.Range(1, VoxelData.chunkWidth); randomPos = chunks[i, j].voxelPositions[randomIndex]; if (IsVoxelInWorld(randomPos) && Noise.Get2DPerlin(new Vector2(randomPos.x, randomPos.z), seed, biome.terrainScale) > 0.65f) { switch (biome.animals[k]) { case AnimalType.Monkey: AnimalFactory.CreateMonkey(5, 10, 50, randomPos, transform); monkeyCount++; break; case AnimalType.Hawk: if (hawkCount < 5) { AnimalFactory.CreateHawk(3, 100, 200, 3, new Vector3(randomPos.x, biome.terrainHeight + 20f, randomPos.z), transform); hawkCount++; } break; } } } } } AnimalStatistics.Instance.SetInitialMonkeyAmount(monkeyCount); AnimalStatistics.Instance.SetInitialHawkAmount(hawkCount); }