HitReactionVRIKTrigger.cs 1002 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. using UnityEngine;
  2. using System.Collections;
  3. using RootMotion.FinalIK;
  4. namespace RootMotion.Demos {
  5. /// <summary>
  6. /// Triggering Hit Reactions on mouse button.
  7. /// </summary>
  8. public class HitReactionVRIKTrigger: MonoBehaviour {
  9. public HitReactionVRIK hitReaction;
  10. public float hitForce = 1f;
  11. private string colliderName;
  12. void Update() {
  13. // On left mouse button...
  14. if (Input.GetMouseButtonDown(0)) {
  15. Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
  16. // Raycast to find a ragdoll collider
  17. RaycastHit hit = new RaycastHit();
  18. if (Physics.Raycast(ray, out hit, 100f)) {
  19. // Use the HitReaction
  20. hitReaction.Hit(hit.collider, ray.direction * hitForce, hit.point);
  21. // Just for GUI
  22. colliderName = hit.collider.name;
  23. }
  24. }
  25. }
  26. void OnGUI() {
  27. GUILayout.Label("LMB to shoot the Dummy, RMB to rotate the camera.");
  28. if (colliderName != string.Empty) GUILayout.Label("Last Bone Hit: " + colliderName);
  29. }
  30. }
  31. }