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.

55 lines
1.3 KiB

  1. using UnityEngine;
  2. using System.Collections;
  3. public class ConnecterOriginal : MonoBehaviour {
  4. private ThrusterOriginal thruster;
  5. private Rigidbody2D rigid;
  6. private bool connected = false;
  7. // Use this for initialization
  8. void Start() {
  9. thruster = GetComponent<ThrusterOriginal>();
  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. Rigidbody2D collRigid = coll.rigidbody;
  19. collRigid.mass += rigid.mass;
  20. thruster.rigid = collRigid;
  21. Destroy(rigid);
  22. transform.parent = coll.transform;
  23. Vector3 tempRot = transform.localEulerAngles;
  24. tempRot.z = Mathf.Round(tempRot.z / 90) * 90;
  25. transform.localRotation = Quaternion.Euler(tempRot);
  26. Vector3 tempPos = transform.localPosition;
  27. float scale = coll.gameObject.GetComponent<BoxCollider2D>().size.x;
  28. tempPos.x = Mathf.Round(tempPos.x / scale) * scale;
  29. tempPos.y = Mathf.Round(tempPos.y / scale) * scale;
  30. transform.localPosition = tempPos;
  31. Destroy(this);
  32. }
  33. }
  34. }