// Update is called once per frame void Update() { if (Input.GetMouseButtonDown (0)) { //left click Vector3 _MP = Input.mousePosition; _MP.z = camera.transform.position.z * -1; //XDebug.Log ("Dir: " + SelectedDirection); if(CurrentMode == PersistentMode.Draw) { if(SelectedBlock!=Blocks.None && SelectedDirection != Directions.None) { //see if block generation is happening over the buttons //Debug.Log (EventSystem.current.currentSelectedGameObject); GameObject current = EventSystem.current.currentSelectedGameObject; if(current == null || (current != cModeExitPanel && current.transform.parent.gameObject != cModeExitPanel)) { GameObject newBlock = null; switch(SelectedBlock) { case Blocks.Basic: //drop a block newBlock = Instantiate(BasicBlock) as GameObject; break; case Blocks.Rocket: //drop a block newBlock = Instantiate(RocketBlock) as GameObject; break; case Blocks.Missile: //drop a block newBlock = Instantiate(MissileBlock) as GameObject; break; case Blocks.Radar: //drop a block newBlock = Instantiate(RadarBlock) as GameObject; break; default: break; } if(newBlock != null) { newBlock.transform.position = Camera.main.ScreenToWorldPoint(_MP); if(newBlock.name.Contains("(Clone)")) newBlock.name = newBlock.name.Replace("(Clone)", ""); //XDebug.Log("Name " + newBlock.name); newBlock.name = newBlock.name + objects++; } } } } else if(CurrentMode == PersistentMode.None) { if(SelectedBlock!=Blocks.None && SelectedDirection == Directions.None) { } else if(SelectedBlock==Blocks.None && SelectedDirection == Directions.None) { RaycastHit hit = new RaycastHit(); Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition); if (Physics.Raycast (ray, out hit)){ //select.tag = "none"; //hit.collider.transform.tag = "select"; GarageObjectScript gos = hit.transform.gameObject.GetComponent<GarageObjectScript>(); if(gos != null) { FocusedGarageBlock = gos; XDebug.Log("Click on: " + gos.Type); if(gos.Type != BlockObjectScript.BlockType.NormalRed || gos.Type != BlockObjectScript.BlockType.NormalBlue) { InputField inf = NameInput.GetComponent<InputField>(); inf.text = gos.name; inf.placeholder.GetComponent<Text>().text = gos.name; NameInput.SetActive(true); } else { NameInput.SetActive(false); } } } } } else if (CurrentMode == PersistentMode.Erase) { RaycastHit hit = new RaycastHit (); Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition); if (Physics.Raycast (ray, out hit)) { //select.tag = "none"; //hit.collider.transform.tag = "select"; GarageObjectScript gos = hit.transform.gameObject.GetComponent<GarageObjectScript> (); if (gos != null) { XDebug.Log ("Click on: " + gos.Type); Destroy (hit.collider.gameObject); //Lose focus of it LoseFocusedGarageBlock(); } } } } if (Input.GetMouseButton (1)) { if (SelectedBlock != Blocks.None && SelectedDirection != Directions.None) { SelectedBlock = Blocks.None; SelectedDirection = Directions.None; ContextSwitch (Context.Main); GameObject panel = blockBuilderCanvas.transform.FindChild("Panel").gameObject; panel.SetActive (true); } else if (SelectedBlock != Blocks.None && SelectedDirection == Directions.None) { SelectedBlock = Blocks.None; SelectedDirection = Directions.None; ContextSwitch (Context.Main); GameObject panel = blockBuilderCanvas.transform.FindChild("Panel").gameObject; panel.SetActive (true); } else if (SelectedBlock == Blocks.None && SelectedDirection == Directions.None) { RaycastHit hit = new RaycastHit (); Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition); if (Physics.Raycast (ray, out hit)) { //select.tag = "none"; //hit.collider.transform.tag = "select"; GarageObjectScript gos = hit.transform.gameObject.GetComponent<GarageObjectScript> (); if (gos != null) { XDebug.Log ("Click on: " + gos.Type); Destroy (hit.collider.gameObject); //Lose focus of it LoseFocusedGarageBlock(); } } } } if(Input.GetKey(KeyCode.UpArrow) && !programmingCanvas.activeSelf){ cameraTo = camera.transform.position; cameraTo.y = cameraTo.y + 5; XDebug.Log("up: " + cameraTo); //camera.transform.position = pos; camera.transform.position = Vector3.Lerp (camera.transform.position, cameraTo, Time.deltaTime * smoothFactor); } if(Input.GetKey(KeyCode.DownArrow) && !programmingCanvas.activeSelf){ cameraTo = camera.transform.position; cameraTo.y = cameraTo.y - 5; XDebug.Log("up: " + cameraTo); camera.transform.position = Vector3.Lerp (camera.transform.position, cameraTo, Time.deltaTime * smoothFactor); } if(Input.GetKey(KeyCode.LeftArrow) && !programmingCanvas.activeSelf){ cameraTo = camera.transform.position; cameraTo.x = cameraTo.x - 5; XDebug.Log("up: " + cameraTo); camera.transform.position = Vector3.Lerp (camera.transform.position, cameraTo, Time.deltaTime * smoothFactor); } if(Input.GetKey(KeyCode.RightArrow) && !programmingCanvas.activeSelf){ cameraTo = camera.transform.position; cameraTo.x = cameraTo.x + 5; XDebug.Log("up: " + cameraTo); camera.transform.position = Vector3.Lerp (camera.transform.position, cameraTo, Time.deltaTime * smoothFactor); } }
public void LoseFocusedGarageBlock() { InputField inf = NameInput.GetComponent<InputField>(); inf.text = ""; inf.placeholder.GetComponent<Text>().text = ""; NameInput.SetActive(false); FocusedGarageBlock = null; }