public void FindPosition() { // create random position Vector3 v3RandPos = new Vector3(); v3RandPos.y = m_fStartYPos; int nGrabbingAxis = Random.Range(0, 2); int nNegative = Random.Range(0, 2); if (nNegative == 0) { nNegative = -1; } switch (nGrabbingAxis) { case 0: v3RandPos.x = m_fOutPositionRange * nNegative; v3RandPos.z = Random.Range(-20.0f, 20.0f); break; case 1: v3RandPos.x = Random.Range(-20.0f, 20.0f); v3RandPos.z = m_fOutPositionRange * nNegative; break; } // set seek location m_v3BombPickupPos = v3RandPos; m_state = BOMBDROPPER_STATE.E_GETTINGBOMB; }
private void Update() { // exits if the bombs have been toggled off if (OptionsManager.InstanceExists && !OptionsManager.Instance.m_bBombs) { return; } // decrement timer if (m_fTimeUntilBombsDrop > 0.0f) { m_fTimeUntilBombsDrop -= Time.deltaTime; } else { m_fDropTimer -= Time.deltaTime; } if (m_fDropTimer <= 0.0f && m_blocks.Count > 0) { switch (m_state) { case BOMBDROPPER_STATE.E_GETTINGBOMB: Vector3 v3Dir = m_v3BombPickupPos - transform.position; if ((m_v3BombPickupPos - transform.position).sqrMagnitude > 1.0f && !m_bReachedLocation) { // move in direction transform.position += v3Dir.normalized * m_fCraneMoveSpeed * Time.deltaTime; } else { m_bReachedLocation = true; // if crane is not down if (transform.position.y >= m_fCraneDownYPosition) { // move down transform.position += Vector3.down * m_fCraneMoveSpeed * Time.deltaTime; } else //if crane is down { // get random block index int nBlockIndex = Random.Range(0, m_blocks.Count); // get bomb position above random block m_v3BombDropPos = m_blocks[nBlockIndex].transform.position; m_v3BombDropPos.y = m_nDropHeight; // create bomb m_currentBomb = Instantiate(m_bomb, transform); m_currentBomb.GetComponent <BlockBomb>().m_nMaxBlocksToDestroy = m_nMaxBlocksToDestroy; m_currentBomb.GetComponent <BlockBomb>().m_bombDropper = gameObject; m_currentBomb.GetComponent <BlockBomb>().enabled = false; m_currentBomb.transform.position = new Vector3(transform.position.x, transform.position.y, transform.position.z); m_state = BOMBDROPPER_STATE.E_HASBOMB; m_bReachedLocation = false; } } break; case BOMBDROPPER_STATE.E_HASBOMB: { // if crane is down if (transform.position.y < m_fStartYPos) { // move crane up transform.position += Vector3.up * m_fCraneDropSpeed * Time.deltaTime; } else { // get direction to drop location Vector3 v3DropDir = m_v3BombDropPos - transform.position; if (v3DropDir.sqrMagnitude > 1.0f) { // seek drop location transform.position += v3DropDir.normalized * m_fCraneMoveSpeed * Time.deltaTime; } else { // drop bomb m_currentBomb.GetComponent <BlockBomb>().enabled = true; m_currentBomb.GetComponent <Rigidbody>().isKinematic = false; m_currentBomb.transform.parent = null; m_state = BOMBDROPPER_STATE.E_RESETTING; ResetTimers(); } } } break; case BOMBDROPPER_STATE.E_RESETTING: FindPosition(); break; } } }