Advertisement
Guest User

Untitled

a guest
Feb 8th, 2016
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class PlatformGenerator : MonoBehaviour {
  5.  
  6. public GameObject thePlatform;
  7. public Transform generationPoint;
  8. public float distanceBetween;
  9.  
  10. private float platformWidth;
  11.  
  12. // Use this for initialization
  13. void Start () {
  14. platformWidth = thePlatform.GetComponent<BoxCollider2D>().size.x;
  15. }
  16.  
  17. // Update is called once per frame
  18. void Update () {
  19.  
  20. if (transform.position.x < generationPoint.position.x)
  21. {
  22. transform.position = new Vector3 (transform.position.x + platformWidth + distanceBetween, transform.position.y, transform.position.z);
  23.  
  24. Instantiate (thePlatform, transform.position, transform.rotation);
  25. }
  26.  
  27. }
  28.  
  29. using UnityEngine;
  30. using System.Collections;
  31.  
  32. public class PlayerControl : MonoBehaviour {
  33.  
  34. public float moveSpeed;
  35. public float jumpForce;
  36.  
  37. private Rigidbody2D myRigidbody;
  38.  
  39. public bool grounded;
  40. public LayerMask whatIsGround;
  41.  
  42. private Collider2D myCollider;
  43.  
  44. private Animator myAnimator;
  45.  
  46. // Use this for initialization
  47. void Start () {
  48. myRigidbody = GetComponent<Rigidbody2D>();
  49. myRigidbody.velocity = new Vector2(moveSpeed, 0);
  50.  
  51. myCollider = GetComponent<Collider2D>();
  52.  
  53. myAnimator = GetComponent<Animator> ();
  54. }
  55.  
  56. // Update is called once per frame
  57. //void Update () {
  58. // myRigidbody.velocity = new Vector2(moveSpeed, myRigidbody.velocity.y);
  59. //
  60. // if(Input.GetKeyDown(KeyCode.Space) || Input.GetMouseButtonDown(0));
  61. // {
  62. // myRigidbody.velocity=new Vector2(myRigidbody.velocity.x, jumpForce);
  63. // }
  64. void Update () {
  65.  
  66. grounded = Physics2D.IsTouchingLayers(myCollider, whatIsGround);
  67.  
  68. if (Input.GetKeyDown(KeyCode.Space))
  69. {
  70. if(grounded)
  71. {
  72. Jump();
  73. }
  74.  
  75. }
  76.  
  77. myAnimator.SetFloat ("Speed", myRigidbody.velocity.x);
  78. myAnimator.SetBool ("Grounded", grounded);
  79.  
  80. }
  81.  
  82. void Jump () {
  83. myRigidbody.AddForce(new Vector2(0, jumpForce));
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement