Guest User

Untitled

a guest
Oct 20th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.93 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using Fungus;
  5.  
  6. public class HareMovement : MonoBehaviour {
  7.  
  8. public float[] jumpElevationInDegrees = { 5, 25, 45};
  9. public float[] jumpSpeedInMPS = {2, 4, 7};
  10. public float jumpGroundClearance = 2;
  11. public float jumpSpeedTolerance = 5;
  12.  
  13. public int collisionCount = 0;
  14. public int hopCount = 0;
  15.  
  16. GvrAudioSource myAudio;
  17. public AudioClip[] myClip;
  18.  
  19. RaycastHit hit;
  20.  
  21. public Flowchart fungusChart;
  22.  
  23.  
  24. void Start ()
  25. {
  26. myAudio = GetComponent<GvrAudioSource>();
  27.  
  28. }
  29.  
  30. void OnCollisionEnter ()
  31. {
  32. collisionCount++;
  33. }
  34.  
  35. void OnCollisionExit ()
  36. {
  37. collisionCount--;
  38. }
  39.  
  40. // Update is called once per frame
  41. void Update ()
  42. {
  43. fungusChart.SetIntegerVariable("hopCount", hopCount);
  44. Physics.Raycast (transform.position, -transform.up, out hit, jumpGroundClearance);
  45. bool isOnPlatform = ((Physics.Raycast (transform.position, -transform.up, jumpGroundClearance)) && (hit.transform.tag == "Platform"));
  46. bool isOnGround = collisionCount > 0;
  47.  
  48. if (isOnPlatform)
  49. {
  50. gameObject.transform.parent = hit.transform;
  51. }
  52. else
  53. {
  54. gameObject.transform.parent = null;
  55. }
  56.  
  57. if (isOnGround) {
  58. hopCount = 0;
  59. }
  60.  
  61.  
  62. if ((Input.GetKeyDown (KeyCode.Space) || GvrViewer.Instance.Triggered) && (hopCount < jumpSpeedInMPS.Length) && (GetComponent<Rigidbody> ().isKinematic == false))
  63. {
  64. var camera = GetComponentInChildren<Camera> ();
  65. var projectedLookDirection = Vector3.ProjectOnPlane (camera.transform.forward, Vector3.up);
  66. var radiansToRotate = Mathf.Deg2Rad * jumpElevationInDegrees [hopCount];
  67. var unnormalizedJumpDirection = Vector3.RotateTowards (projectedLookDirection, Vector3.up, radiansToRotate, 0);
  68. var jumpVector = unnormalizedJumpDirection.normalized * jumpSpeedInMPS [hopCount];
  69. GetComponent<Rigidbody> ().AddForce (jumpVector, ForceMode.VelocityChange);
  70. myAudio.PlayOneShot (myClip [hopCount]);
  71. fungusChart.ExecuteBlock("OnJump");
  72. hopCount++;
  73. }
  74. }
  75.  
  76. }
Add Comment
Please, Sign In to add comment