Advertisement
Guest User

Untitled

a guest
May 2nd, 2017
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.75 KB | None | 0 0
  1. public class Player : MonoBehaviour {
  2.     private bool hasLanded = true;
  3.     private bool go = false;
  4.     public float speed = 20f;
  5.     public Rigidbody2D rb;
  6.     public SpriteRenderer sprt;
  7.     public ColorChanger colorChanger;
  8.     public ParticlesSpawner particleSpawner;
  9.     private void FixedUpdate()
  10.     {
  11.         if (Input.GetButton("Fire1") || Input.GetButton("Jump"))
  12.         {
  13.             go = true;
  14.         }
  15.             if (!hasLanded || go == true)
  16.             {
  17.             transform.parent = null;
  18.             rb.MovePosition(transform.position += transform.up * Time.deltaTime * speed);    
  19.         }
  20.        
  21.     }
  22. private void OnTriggerEnter2D(Collider2D collision)
  23.     {
  24.         if (collision.tag == "Platforms")
  25.         {
  26.             go = false; // stops the player, until he presses "fire" button
  27.             hasLanded = true; //checking if a player has landed for the first time, only used in the beggining of the game
  28.             transform.SetParent(collision.transform);
  29.             Vector2 circleNormal = transform.position - collision.transform.position;
  30.             Quaternion rot = Quaternion.FromToRotation(Vector2.up, circleNormal);
  31.             transform.rotation = rot;
  32.             collision.GetComponent<Rotator>().speed = Random.Range(150, 250);
  33.             float rad = collision.GetComponent<CircleCollider2D>().radius * transform.localScale.x;
  34.             transform.position = circleNormal.normalized * rad;
  35.             particleSpawner.landParticleSpawner(transform.position, collision); //ignore
  36.             colorChanger.ColorSwitch();  //ignore
  37.         } else if (collision.tag == "Dividers")
  38.         {      
  39.             SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
  40.         }
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement