private void Update() { if (Input.touchCount > 0) { Touch touch = Input.GetTouch(0); if (!EventSystem.current.IsPointerOverGameObject(touch.fingerId)) { if (touch.phase == TouchPhase.Began) { if (m_selectedTool == Tool.place) { if (Stats.Sheet.m_rockCount < m_maxStones) { Ray ray = m_mainCamera.ScreenPointToRay(touch.position); RaycastHit hit; if (Physics.Raycast(ray, out hit, m_terrainLayer)) { if (m_placeAllowed) { if (hit.point.y < m_maxRockHeight) { StartCoroutine(DelayRock()); Vector3 spawnPoint = hit.point + m_placeOffset; ObjectPooler.SpawnObject(m_rockName, spawnPoint + m_placeOffset, Quaternion.identity, true); Stats.Sheet.m_rockCount++; } } } } } else { Ray ray = m_mainCamera.ScreenPointToRay(touch.position); RaycastHit hit; if (Physics.Raycast(ray, out hit, m_removeLayer)) { IRemovable removable = hit.collider.GetComponent <IRemovable>(); if (removable != null) { removable.OnRemove(); } } } } } } }
// __________________________________________________________________________________________ // remove objects - the ugly part - hoe versimpelen? // __________________________________________________________________________________________ public void CheckRemovables() { for (int i = _gameobjects.Count - 1; i >= 0; i--) { GameObject go = _gameobjects[i]; // remove if (go is IRemovable) { IRemovable rmv = go as IRemovable; if (rmv.RemoveMe == true) { rmv.OnRemove(this); _gameobjects.Remove(go); } } } }