// Update is called once per frame void Update() { ScreechFrequency -= ScreechFalloff; ScreechFrequency = Mathf.Clamp(ScreechFrequency, 0, 1); sawSoundEmitter.SetParameter("VolumeParameter", ScreechFrequency); if (isSawing) { float xVel = sawRigidbody.gameObject.transform.InverseTransformDirection(sawRigidbody.velocity).x; if (Mathf.Abs(xVel) > sawThreshold) { sawRigidbody.AddForce(-sawRigidbody.transform.up * 100, ForceMode2D.Impulse); if (currentSawableObject != null) { currentSawableObject.GetSawed(-sawRigidbody.transform.up); if (MasterControl.Instance != null) { MasterControl.Instance.Screenshake(0.2f); } Screech(0.1f); GameObject obj = Instantiate(blood); obj.transform.position = currentSawableObject.GetCollisionPoint(); Quaternion bloodRotation = Quaternion.LookRotation (currentSawableObject.GetCollisionNormal() - (Vector3)sawRigidbody.velocity, transform.TransformDirection(Vector3.down)); obj.transform.rotation = Quaternion.FromToRotation(Vector3.back, new Vector3(currentSawableObject.GetCollisionNormal().x *(2 * xVel), currentSawableObject.GetCollisionNormal().y, currentSawableObject.GetCollisionNormal().z)); } } //sawRigidbod.constraints = RigidbodyConstraints2D.FreezePositionY; } else { if (currentSawableObject != null) { currentSawableObject.EndSaw(); currentSawableObject = null; //sawRigidbod.constraints = RigidbodyConstraints2D.None; } } }
public void ProceedSaw(ISawable sawableObject) { isSawing = true; currentSawableObject = sawableObject; }