Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class PlatformGenerator : MonoBehaviour {
- public GameObject thePlatform;
- public Transform generationPoint;
- public float distanceBetween;
- private float platformWidth;
- // Use this for initialization
- void Start () {
- platformWidth = thePlatform.GetComponent<BoxCollider2D>().size.x;
- }
- // Update is called once per frame
- void Update () {
- if (transform.position.x < generationPoint.position.x)
- {
- transform.position = new Vector3 (transform.position.x + platformWidth + distanceBetween, transform.position.y, transform.position.z);
- Instantiate (thePlatform, transform.position, transform.rotation);
- }
- }
- using UnityEngine;
- using System.Collections;
- public class PlayerControl : MonoBehaviour {
- public float moveSpeed;
- public float jumpForce;
- private Rigidbody2D myRigidbody;
- public bool grounded;
- public LayerMask whatIsGround;
- private Collider2D myCollider;
- private Animator myAnimator;
- // Use this for initialization
- void Start () {
- myRigidbody = GetComponent<Rigidbody2D>();
- myRigidbody.velocity = new Vector2(moveSpeed, 0);
- myCollider = GetComponent<Collider2D>();
- myAnimator = GetComponent<Animator> ();
- }
- // Update is called once per frame
- //void Update () {
- // myRigidbody.velocity = new Vector2(moveSpeed, myRigidbody.velocity.y);
- //
- // if(Input.GetKeyDown(KeyCode.Space) || Input.GetMouseButtonDown(0));
- // {
- // myRigidbody.velocity=new Vector2(myRigidbody.velocity.x, jumpForce);
- // }
- void Update () {
- grounded = Physics2D.IsTouchingLayers(myCollider, whatIsGround);
- if (Input.GetKeyDown(KeyCode.Space))
- {
- if(grounded)
- {
- Jump();
- }
- }
- myAnimator.SetFloat ("Speed", myRigidbody.velocity.x);
- myAnimator.SetBool ("Grounded", grounded);
- }
- void Jump () {
- myRigidbody.AddForce(new Vector2(0, jumpForce));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement