mirror of
https://github.com/zoriya/Mimireisu.git
synced 2026-06-02 18:41:56 +00:00
Changed add and remove of mi methods.
This commit is contained in:
@@ -4,11 +4,20 @@ public class Earthworm : MonoBehaviour
|
||||
{
|
||||
public GameObject MiPrefab;
|
||||
public float force = 10;
|
||||
private Rigidbody2D rb;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
rb = transform.GetChild(0).GetComponent<Rigidbody2D>();
|
||||
}
|
||||
|
||||
void Update ()
|
||||
{
|
||||
float movement = Input.GetAxis("Horizontal");
|
||||
//rb.AddForce(new Vector2(movement * force, 0));
|
||||
float horizontal = Input.GetAxis("Horizontal");
|
||||
float vertical = Input.GetAxis("Vertical");
|
||||
Vector2 movement = new Vector2(horizontal, vertical).normalized;
|
||||
//HingeJoint2D joint = new HingeJoint2D();
|
||||
//joint.
|
||||
|
||||
if (Input.GetKeyDown(KeyCode.Space))
|
||||
AddMi();
|
||||
@@ -20,10 +29,12 @@ public class Earthworm : MonoBehaviour
|
||||
void AddMi()
|
||||
{
|
||||
Transform tsu = transform.GetChild(transform.childCount - 1);
|
||||
Vector3 distance = tsu.localPosition - transform.GetChild(transform.childCount - 2).localPosition;
|
||||
GameObject mi = Instantiate(MiPrefab, transform);
|
||||
|
||||
mi.transform.localPosition = tsu.localPosition;
|
||||
tsu.SetAsLastSibling();
|
||||
tsu.localPosition = new Vector2(0.4f * (transform.childCount - 1), tsu.position.y);
|
||||
tsu.localPosition = mi.transform.localPosition + distance;
|
||||
tsu.GetComponent<HingeJoint2D>().connectedBody = mi.GetComponent<Rigidbody2D>();
|
||||
mi.GetComponent<HingeJoint2D>().connectedBody = transform.GetChild(transform.childCount - 3).GetComponent<Rigidbody2D>();
|
||||
}
|
||||
@@ -35,7 +46,7 @@ public class Earthworm : MonoBehaviour
|
||||
Transform tsu = transform.GetChild(transform.childCount - 1);
|
||||
Transform mi = transform.GetChild(transform.childCount - 2);
|
||||
Transform lastMi = transform.GetChild(transform.childCount - 3);
|
||||
Vector2 pos = mi.position;
|
||||
Vector2 pos = mi.localPosition;
|
||||
Destroy(mi.gameObject);
|
||||
tsu.localPosition = pos;
|
||||
tsu.GetComponent<HingeJoint2D>().connectedBody = lastMi.GetComponent<Rigidbody2D>();
|
||||
|
||||
Reference in New Issue
Block a user