You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

56 lines
1.3 KiB

  1. using UnityEngine;
  2. using System.Collections;
  3. public class Connecter : MonoBehaviour {
  4. private Thruster thruster;
  5. private Rigidbody2D rigid;
  6. private bool connected = false;
  7. // Use this for initialization
  8. void Start () {
  9. thruster = GetComponent<Thruster>();
  10. rigid = GetComponent<Rigidbody2D>();
  11. }
  12. // Update is called once per frame
  13. void Update () {
  14. }
  15. void OnCollisionEnter2D(Collision2D coll) {
  16. if (coll.gameObject.tag == "Player" && !connected) {
  17. connected = true;
  18. thruster.attached = true;
  19. Rigidbody2D collRigid = coll.rigidbody;
  20. collRigid.mass += rigid.mass;
  21. thruster.rigid = collRigid;
  22. Destroy(rigid);
  23. transform.parent = coll.transform;
  24. Vector3 tempRot = transform.localEulerAngles;
  25. tempRot.z = Mathf.Round(tempRot.z / 90) * 90;
  26. transform.localRotation = Quaternion.Euler(tempRot);
  27. Vector3 tempPos = transform.localPosition;
  28. float scale = coll.gameObject.GetComponent<BoxCollider2D>().size.x;
  29. tempPos.x = Mathf.Round(tempPos.x / scale) * scale;
  30. tempPos.y = Mathf.Round(tempPos.y / scale) * scale;
  31. transform.localPosition = tempPos;
  32. Destroy(this);
  33. }
  34. }
  35. }