public void Attach(GameObject newTarget, Vector3 attachPos) { // TODO attach to the target! extender = null; CreateSegments(attachPos); if (newTarget != null) { AudioSource.PlayClipAtPoint(attachSound, Camera.main.transform.position); target = newTarget.GetComponent <HingeJoint2D>(); target.connectedBody = links[links.Length - 1].GetComponent <Rigidbody2D>(); target.anchor = target.transform.InverseTransformPoint(attachPos); target.enabled = true; target.SendMessage("TongueAttached", attachPos, SendMessageOptions.DontRequireReceiver); } }
public void Detach() { if (links != null) { foreach (TongueLink link in links) { Destroy(link.gameObject); } links = null; } if (target != null) { target.SendMessage("TongueDetached", SendMessageOptions.DontRequireReceiver); target.enabled = false; target = null; } }