public void attach(RodBalance weight) { parent[location] = weight; weight.myCol.enabled = false; weight.transform.position = transform.GetChild(0).position; weight.transform.SetParent(transform); occupied = true; GameManager.solved[6] = true; }
public RodBalance detach() { RodBalance temp = parent[location]; temp.myCol.enabled = true; temp.transform.rotation = Quaternion.identity; temp.transform.SetParent(null); parent[location] = null; occupied = false; return(temp); }
void Update() { if (castAllowed && !GetComponent <ShowInstructions>().instructions.activeSelf) { if (Input.GetButtonDown("Click")) { if (!equipped) { RaycastHit hit; Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(ray, out hit, 50, 1 << 10)) { if (hit.collider.CompareTag("Hook") && hit.collider.GetComponent <Hook>().occupied) { equipped = hit.collider.GetComponent <Hook>().detach(); torque = calculateRotationOfAllBalances(); return; } } if (!equipped && Physics.Raycast(ray, out hit, 50, 1 << 11)) { if (hit.collider.CompareTag("Weight") && hit.collider.GetComponent <RodBalance>().equipable) { equipped = hit.collider.GetComponent <RodBalance>(); } } } else { RaycastHit hit; Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(ray, out hit, 50)) { if (hit.collider.CompareTag("Hook") && !hit.collider.GetComponent <Hook>().occupied) { hit.collider.GetComponent <Hook>().attach(equipped); equipped = null; torque = calculateRotationOfAllBalances(); } } } } else if (Input.GetButtonDown("Exit") && equipped) { equipped.transform.position = equipped.primaryLocation; equipped = null; } if (equipped) { equipped.transform.position = player.position + player.transform.forward * 3; } } }