spacepaste

  1.  
  2. using System;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using Unity;
  6. using UnityEngine;
  7. using UnityStandardAssets.CrossPlatformInput;
  8. public class newjump : MonoBehaviour {
  9. Rigidbody R;
  10. public float force = 375f;
  11. public bool grounded = false;
  12. public float ColliderEdge;
  13. CharacterController C;
  14. // Use this for initialization
  15. void Start () {
  16. ColliderEdge = GetColliderEdge();
  17. R = GetComponent<Rigidbody>();
  18. C = GetComponent<CharacterController>();
  19. }
  20. // Update is called once per frame
  21. void Update () {
  22. grounded = IsGrounded();
  23. if (grounded) if (Input.GetButton("Jump")) R.AddForce(Vector3.up * force, ForceMode.Impulse);
  24. printfTools.Tools.fprintf(Debug.Log, "Physics.Raycast(transform.position, hitInfo, ColliderEdge) = %s", grounded?"true":"false");
  25. }
  26. float GetColliderEdge()
  27. {
  28. if (GetComponent<Collider>().GetType() == typeof(SphereCollider))
  29. {
  30. return GetComponent<SphereCollider>().radius;
  31. }
  32. return 0f;
  33. }
  34. bool IsGrounded()
  35. {
  36. RaycastHit hitInfo;
  37. return Physics.Raycast(transform.position, -Vector3.up, out hitInfo, ColliderEdge);
  38. }
  39. }
  40.