Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using Fungus;
- public class HareMovement : MonoBehaviour {
- public float[] jumpElevationInDegrees = { 5, 25, 45};
- public float[] jumpSpeedInMPS = {2, 4, 7};
- public float jumpGroundClearance = 2;
- public float jumpSpeedTolerance = 5;
- public int collisionCount = 0;
- public int hopCount = 0;
- GvrAudioSource myAudio;
- public AudioClip[] myClip;
- RaycastHit hit;
- public Flowchart fungusChart;
- void Start ()
- {
- myAudio = GetComponent<GvrAudioSource>();
- }
- void OnCollisionEnter ()
- {
- collisionCount++;
- }
- void OnCollisionExit ()
- {
- collisionCount--;
- }
- // Update is called once per frame
- void Update ()
- {
- fungusChart.SetIntegerVariable("hopCount", hopCount);
- Physics.Raycast (transform.position, -transform.up, out hit, jumpGroundClearance);
- bool isOnPlatform = ((Physics.Raycast (transform.position, -transform.up, jumpGroundClearance)) && (hit.transform.tag == "Platform"));
- bool isOnGround = collisionCount > 0;
- if (isOnPlatform)
- {
- gameObject.transform.parent = hit.transform;
- }
- else
- {
- gameObject.transform.parent = null;
- }
- if (isOnGround) {
- hopCount = 0;
- }
- if ((Input.GetKeyDown (KeyCode.Space) || GvrViewer.Instance.Triggered) && (hopCount < jumpSpeedInMPS.Length) && (GetComponent<Rigidbody> ().isKinematic == false))
- {
- var camera = GetComponentInChildren<Camera> ();
- var projectedLookDirection = Vector3.ProjectOnPlane (camera.transform.forward, Vector3.up);
- var radiansToRotate = Mathf.Deg2Rad * jumpElevationInDegrees [hopCount];
- var unnormalizedJumpDirection = Vector3.RotateTowards (projectedLookDirection, Vector3.up, radiansToRotate, 0);
- var jumpVector = unnormalizedJumpDirection.normalized * jumpSpeedInMPS [hopCount];
- GetComponent<Rigidbody> ().AddForce (jumpVector, ForceMode.VelocityChange);
- myAudio.PlayOneShot (myClip [hopCount]);
- fungusChart.ExecuteBlock("OnJump");
- hopCount++;
- }
- }
- }
Add Comment
Please, Sign In to add comment