Advertisement
Guest User

Untitled

a guest
Jan 16th, 2019
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class PlayerController : MonoBehaviour {
  6.  
  7. public SpriteRenderer sprite;
  8. public LayerMask groundLayer;
  9. public Transform groundCheck;
  10. public float groundCheckRadius;
  11. private bool groundCollision;
  12. // Add code here
  13.  
  14.  
  15. void Start () {
  16.  
  17. }
  18.  
  19. void FixedUpdate () {
  20. groundCollision = Physics2D.OverlapCircle (groundCheck.position, groundCheckRadius, groundLayer);
  21. }
  22.  
  23. void Update () {
  24. var rigidBody = GetComponent<Rigidbody2D> ();
  25. var transform = GetComponent<Transform> ();
  26.  
  27. if (Input.GetKey ("right")) {
  28. sprite.flipX = false;
  29. rigidBody.velocity = new Vector2 (5, rigidBody.velocity.y);
  30. }
  31.  
  32. if (Input.GetKey ("left")) {
  33. sprite.flipX = true;
  34. rigidBody.velocity = new Vector2 (-5, rigidBody.velocity.y);
  35. }
  36.  
  37. // Add code here
  38.  
  39. if (Input.GetKeyDown ("space") && groundCollision) {
  40. rigidBody.velocity = new Vector2 (rigidBody.velocity.x, 10);
  41. }
  42.  
  43. if (transform.position.y < -6) {
  44. if (transform.position.x < 2) {
  45. transform.position = new Vector2 (-5, 2);
  46. } else {
  47. transform.position = new Vector2 (2, 2);
  48. }
  49. }
  50. }
  51.  
  52. public void OnTriggerEnter2D (Collider2D other) {
  53. if (other.name == "EnemyDamage") {
  54. transform.position = new Vector2 (2, 1);
  55. }
  56. }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement