public void reset() { if (selected) { rend.material.shader = shader1; MoveBody MoveBody = selected.GetComponent <MoveBody>(); MoveBody.enabled = false; } isSelected = false; selected = null; rend = null; }
void Update() { if (Input.GetMouseButtonDown(0)) // LMB { RaycastHit hit; Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(ray, out hit, 100.0f)) { if (hit.transform != null && hit.transform.gameObject.tag == "Movable") { reset(); PrintName(hit.transform.gameObject); if (rb = hit.transform.GetComponent <Rigidbody>()) { isSelected = true; selected = hit.transform.gameObject; rend = selected.GetComponent <Renderer>(); } } } } if (selected && isSelected) { rend.material.shader = shader2; MoveBody MoveBody = selected.GetComponent <MoveBody>(); MoveBody.enabled = true; } else if (selected) { rend.material.shader = shader1; MoveBody MoveBody = selected.GetComponent <MoveBody>(); MoveBody.enabled = false; isSelected = false; } else { rend.material.shader = shader1; selected = null; rend = null; } }
void Start() { _moveBody = GetComponent <MoveBody>(); }