// Start is called before the first frame update void Start() { if (RefreshPrefs) { PlayerPrefs.DeleteAll(); } //create and index blocks to their input selection space; left/mid/right, 1-5/6-10/.. blocksPerFloor = middleSection + rightSection + leftSection; SelectionLock = false; IsSelectionState = false; if (blockPrefab != null) { float xPos = this.gameObject.transform.position.x; float yPos = this.gameObject.transform.position.y; for (int y = 0; y < floors; y++) { for (int x = 0; x < blocksPerFloor; x++) { BlockPrefab block = Instantiate(blockPrefab, new Vector3(xPos, yPos, this.gameObject.transform.position.z), Quaternion.identity, this.transform); block.Index = x + blocksPerFloor * y; block.SetColor(defaultColor); blocks.Add(block); xPos += xOffset[x % xOffset.Length]; } xPos = this.gameObject.transform.position.x; yPos += yOffset[y % yOffset.Length]; } } //turns off to hide this gameObject.SetActive(false); }
public void PlayerHandItemChange(int geoCode) { for (int childIndex = 1; childIndex < playerRightHandGameObject.transform.childCount; childIndex++) { ItemPool.instance.ReturnHandGameObjectToPool(playerRightHandGameObject.transform.GetChild(childIndex).gameObject); } if (geoCode != 0) { GameObject handItem = ItemPool.instance.GetItemHandBlockGameObjectFromPool(geoCode); handItem.transform.SetParent(playerRightHandGameObject.transform, false); playerRightHandBlockPrefabInfo = handItem.GetComponent <BlockPrefab>(); } else { playerRightHandBlockPrefabInfo = null; //handPrefab } }
public void onBlockClicked(BlockPrefab blockPrefab) { // Trigger when Block is clicked if (inGame) { if (blockPrefab.Value == levels[levelCount - 1].LevelValue) { MusicController.Instance.rightSound.Play(); levelCount++; reactTimer = reactTime; NextLevel(levelCount); } else { MusicController.Instance.wrongSound.Play(); GameOver(); } } }
public void PlayerHandItemChange(int fastInventoryIndex) { InventoryEntry entry = playerInventory.fastInventory[fastInventoryIndex]; curSelectedFastInventoryIndex = fastInventoryIndex; for (int childIndex = 1; childIndex < playerRightHandGameObject.transform.childCount; childIndex++) { ItemPool.instance.ReturnHandGameObjectToPool(playerRightHandGameObject.transform.GetChild(childIndex).gameObject); } if (entry.m_geoCode != 0) { GameObject handItem = ItemPool.instance.GetItemHandBlockGameObjectFromPool(entry.m_geoCode); handItem.transform.SetParent(playerRightHandGameObject.transform, false); playerRightHandBlockPrefabInfo = handItem.GetComponent <BlockPrefab>(); } else { playerRightHandBlockPrefabInfo = null; //handPrefab } }
// Update is called once per frame void Update() { if (Input.GetMouseButtonUp(0)) { SelectionLock = false; } if (!SelectionLock && IsSelectionState) { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit, 1000)) { Debug.DrawLine(ray.origin, hit.point); //Debug.Log(hit.transform.gameObject.name); switch (hit.collider.tag) { case "BuildingBlock": BlockPrefab block = hit.transform.gameObject.GetComponent <BlockPrefab>(); int blockIndex = block.Index; Debug.Log(string.Format("index: {0}; unitId: {1}", block.Index, block.UnitId)); SelectUnitBlocks(blockIndex); break; default: break; } //Debug.Log(blockIndex); //Debug.Log("hit"); } else { ClearSelectedBlocks(); } } }
private void Awake() { blockPrefabInfo = GetComponent <BlockPrefab>(); }
private void generateBlock(string block, Vector3 position) { GameObject cloneBlock = GameObject.FindWithTag(block); BlockPrefab.InstantiateBlock(cloneBlock, position); }
/* * Do interact motion. Setup block or open chest */ IEnumerator AnimInteractStartCorutine() { float animIntervalHitTime = 0.6f; float animIntervalTime = 0.8f; float missAudioIntervalTime = 0.24f; float curTime = 0.0f; RaycastHit hit; Ray ray; Vector3 monitorCenterViewport = new Vector3(0.5f, 0.5f, 0f); //ray with center of camera //float blockCheckDistance = 1.5f; //pick distance bool isRayChecked = false; bool isMissAudioPlayed = false; int rayHItWithBlockOrEnemy = (1 << PlayerHash.BlockLayer); float rightHandBlockDigDistance; if (playerRightHandBlockPrefabInfo == null) { rightHandBlockDigDistance = 3.0f; } else { rightHandBlockDigDistance = playerRightHandBlockPrefabInfo.m_blockDigDistance; } playerAnimator.SetTrigger(PlayerHash.MiningStartID); do { yield return(null); if (isNewState) { break; } //check if state is changed before start. if (curTime > missAudioIntervalTime && !isMissAudioPlayed) { PlayAudioClip(playerSoundClip.attackMissSound); isMissAudioPlayed = true; //False when animation 1 loop end } // start block check if (curTime > animIntervalHitTime && !isRayChecked) { isRayChecked = true; ray = charViewCamera.ViewportPointToRay(monitorCenterViewport); if (Physics.Raycast(ray, out hit, rightHandBlockDigDistance, rayHItWithBlockOrEnemy)) { Transform objectHit = hit.transform; if (objectHit.CompareTag("Block")) { GameObject recentBlockGameobject = objectHit.gameObject; BlockPrefab recentBlockPrefab = recentBlockGameobject.GetComponent <BlockPrefab>(); if (recentBlockPrefab.m_isChest) { //TODO : chest open } else if (playerRightHandBlockPrefabInfo != null && playerRightHandBlockPrefabInfo.m_canSetupBlock) { //block setup PlayAudioClip(playerSoundClip.blockSetupSound); Vector3 hitPointVec3 = hit.point; Vector3 recentBlockPosition = recentBlockGameobject.transform.position; float border = 0.49f; Vector3 halfCheckExtents = new Vector3(0.45f, 0.45f, 0.45f); if (hitPointVec3.x - recentBlockPosition.x > border) { if (!Physics.CheckBox(recentBlockPosition + new Vector3(1.0f, 0.0f, 0.0f), halfCheckExtents)) { //nothing in box. SceneManager.instance.AddBlock(recentBlockPosition + new Vector3(1.0f, 0.0f, 0.0f), (playerRightHandBlockPrefabInfo.m_geoCode)); PlayerInventory.instance.UseItemInFastInventory(curSelectedFastInventoryIndex, 1); } else { Debug.Log("checkbox problem"); } } else if (hitPointVec3.x - recentBlockPosition.x < -border) { if (!Physics.CheckBox(recentBlockPosition + new Vector3(-1.0f, 0.0f, 0.0f), halfCheckExtents)) { //nothing in box. SceneManager.instance.AddBlock(recentBlockPosition + new Vector3(-1.0f, 0.0f, 0.0f), (playerRightHandBlockPrefabInfo.m_geoCode)); PlayerInventory.instance.UseItemInFastInventory(curSelectedFastInventoryIndex, 1); } else { Debug.Log("checkbox problem"); } } else if (hitPointVec3.y - recentBlockPosition.y > border) { if (!Physics.CheckBox(recentBlockPosition + new Vector3(0.0f, 1.0f, 0.0f), halfCheckExtents)) { //nothing in box. SceneManager.instance.AddBlock(recentBlockPosition + new Vector3(0.0f, 1.0f, 0.0f), (playerRightHandBlockPrefabInfo.m_geoCode)); PlayerInventory.instance.UseItemInFastInventory(curSelectedFastInventoryIndex, 1); } else { Debug.Log("checkbox problem"); } } else if (hitPointVec3.y - recentBlockPosition.y < -border) { if (!Physics.CheckBox(recentBlockPosition + new Vector3(0.0f, -1.0f, 0.0f), halfCheckExtents)) { //nothing in box. SceneManager.instance.AddBlock(recentBlockPosition + new Vector3(0.0f, -1.0f, 0.0f), (playerRightHandBlockPrefabInfo.m_geoCode)); PlayerInventory.instance.UseItemInFastInventory(curSelectedFastInventoryIndex, 1); } else { Debug.Log("checkbox problem"); } } else if (hitPointVec3.z - recentBlockPosition.z > border) { if (!Physics.CheckBox(recentBlockPosition + new Vector3(0.0f, 0.0f, 1.0f), halfCheckExtents)) { //nothing in box. SceneManager.instance.AddBlock(recentBlockPosition + new Vector3(0.0f, 0.0f, 1.0f), (playerRightHandBlockPrefabInfo.m_geoCode)); PlayerInventory.instance.UseItemInFastInventory(curSelectedFastInventoryIndex, 1); } else { Debug.Log("checkbox problem"); } } else if (hitPointVec3.z - recentBlockPosition.z < -border) { if (!Physics.CheckBox(recentBlockPosition + new Vector3(0.0f, 0.0f, -1.0f), halfCheckExtents)) { //nothing in box. SceneManager.instance.AddBlock(recentBlockPosition + new Vector3(0.0f, 0.0f, -1.0f), (playerRightHandBlockPrefabInfo.m_geoCode)); PlayerInventory.instance.UseItemInFastInventory(curSelectedFastInventoryIndex, 1); } else { Debug.Log("checkbox problem"); } } } } else { //no hit block } } } else if (curTime > animIntervalTime) { //init curTime & Re Loop Raycheck curTime = 0.0f; isRayChecked = false; isMissAudioPlayed = false; SetNewState(PlayerState.AnimInteractEndCorutine); } curTime += Time.deltaTime; }while (!isNewState); //check if state is changed in this corutine. }