public void BuildControlles() { if (subject != null) { subject.transform.position = Owner.transform.position + ((Owner.transform.forward * 8) + Owner.transform.up * 10); } if (Input.GetKeyDown(KeyCode.O)) { if (Mode == BuildMode.Turrets) { if (Ttype != TurretTypes.last && subject == null) { Debug.Log("Getting Turret"); subject = ConstructDirectory.GetTurret(Ttype); } else { if (subject.GetComponent <IPlaceableObj>().Place(subject.transform.position)) { subject = null; } } } else if (Mode == BuildMode.Wall) { Ray r = new Ray(Owner.transform.position + Owner.transform.forward * 8, Vector3.down); Debug.Log("Click: " + r.origin); RaycastHit hit; Debug.DrawRay(r.origin, r.direction * 10f, Color.red); if (Physics.Raycast(r, out hit, Mathf.Infinity)) { Debug.Log("Hit."); IClickable c = hit.collider.gameObject.GetComponent <IClickable>(); if (c != null) { Debug.Log("Click action: " + hit.point); c.ClickAction(hit.point); } } } else { Debug.Log("Error Build mode not set correctly"); } } else if (Input.GetKeyDown(KeyCode.P)) { if (subject != null) { GameObject.Destroy(subject.gameObject); subject = null; isBuilding = false; Mode = BuildMode.last; } } }
// Update is called once per frame void Update() { if (Input.GetMouseButtonDown(0)) { Ray r = Camera.main.ScreenPointToRay(Input.mousePosition); // Debug.Log("Click: " + r.origin); RaycastHit hit; Debug.DrawRay(r.origin, r.direction * 10f, Color.red); if (Physics.Raycast(r, out hit, Mathf.Infinity)) { // Debug.Log("Hit."); IClickable c = hit.collider.gameObject.GetComponent <IClickable>(); if (c != null) { Debug.Log("Click action: " + hit.point); c.ClickAction(hit.point); } } } }