Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Player : MonoBehaviour {
- private bool hasLanded = true;
- private bool go = false;
- public float speed = 20f;
- public Rigidbody2D rb;
- public SpriteRenderer sprt;
- public ColorChanger colorChanger;
- public ParticlesSpawner particleSpawner;
- private void FixedUpdate()
- {
- if (Input.GetButton("Fire1") || Input.GetButton("Jump"))
- {
- go = true;
- }
- if (!hasLanded || go == true)
- {
- transform.parent = null;
- rb.MovePosition(transform.position += transform.up * Time.deltaTime * speed);
- }
- }
- private void OnTriggerEnter2D(Collider2D collision)
- {
- if (collision.tag == "Platforms")
- {
- go = false; // stops the player, until he presses "fire" button
- hasLanded = true; //checking if a player has landed for the first time, only used in the beggining of the game
- transform.SetParent(collision.transform);
- Vector2 circleNormal = transform.position - collision.transform.position;
- Quaternion rot = Quaternion.FromToRotation(Vector2.up, circleNormal);
- transform.rotation = rot;
- collision.GetComponent<Rotator>().speed = Random.Range(150, 250);
- float rad = collision.GetComponent<CircleCollider2D>().radius * transform.localScale.x;
- transform.position = circleNormal.normalized * rad;
- particleSpawner.landParticleSpawner(transform.position, collision); //ignore
- colorChanger.ColorSwitch(); //ignore
- } else if (collision.tag == "Dividers")
- {
- SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement