// Update is called once per frame void Update() { if (isSelected) { if (Input.GetMouseButtonDown(1)) { Ray ray = cam.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit)) { // GameObject square = hit.collider.gameObject; //Color color = square.GetComponent<Color>(); //color = Color.yellow; if (playerBench) { playerBench = false; _bench.unOccupy(); } _bench = null; GameObject currBoard = findNearestBoard(this.transform.position); if (currBoard != null) { if (currBoard.GetComponent <Board_block>() != null) { Board_block instance = currBoard.GetComponent <Board_block>(); instance.unOccupy(); } } this.transform.position = findBoard(hit.point); currBoard = findNearestBoard(this.transform.position); if (currBoard != null) { if (currBoard.GetComponent <Board_block>() != null) { Board_block instance = currBoard.GetComponent <Board_block>(); instance.occupy(); } } isSelected = false; } } else if (Input.GetKeyUp("b")) { if (_bench != null) { _bench.unOccupy(); } playerBench = false; sendToBench(); isSelected = false; } } }
private void Start() { cam = Camera.main; _bench = GameObject.Find("Bench").GetComponent <Bench_Script>(); if (_bench == null) { Debug.Log("The bench messed up"); } if (playerBench == false) { sendToBench(); } }