private void OnTriggerEnter(Collider other) { Stickable stickable = other.GetComponent <Stickable>(); if (stickable != null && !other.isTrigger) { stickable.SetSticked(this); SoundManagerScript.instance.PlayOneShotSound(SoundManagerScript.AudioClips.ObjectPutWorkbench); } }
private void OnCollisionEnter(Collision other) { stickable = other.gameObject.GetComponentInChildren <Stickable>(); if (stickable) { stickyObj = stickable.gameObject; arrowRigid.constraints = RigidbodyConstraints.FreezeAll; arrowRigid.gameObject.transform.parent = stickyObj.transform; } }
private Stickable CheckStickable(Vector3 direction) { RaycastHit hit; Stickable stickable = null; if (Physics.Raycast(transform.position, transform.TransformDirection(direction), out hit, RAYCAST_DISTANCE)) { stickable = hit.transform.gameObject.GetComponent <Stickable>(); } return(stickable); }
public void Stick(Stickable stickable) { stuck.Add(stickable.gameObject); var collisionDistance = Vector3.Distance(transform.position, stickable.gameObject.transform.position); var springJoint = gameObject.AddComponent <SpringJoint>(); springJoint.damper = 1.5f; springJoint.spring = 0f; springJoint.enableCollision = true; springJoint.minDistance = 0f; springJoint.maxDistance = collisionDistance * 1.05f; springJoint.tolerance = 1f; springJoint.connectedBody = stickable.GetComponent <Rigidbody>(); }