Changed add and remove of mi methods.

This commit is contained in:
Anonymous Raccoon
2018-05-28 21:05:24 +02:00
parent d2c72e8560
commit 671c9e1382
3 changed files with 18 additions and 39 deletions

View File

@@ -76,7 +76,6 @@ GameObject:
m_Component:
- component: {fileID: 4937824842681064}
- component: {fileID: 114231868638308982}
- component: {fileID: 50022655303262748}
m_Layer: 0
m_Name: Mimitsu
m_TagString: Untagged
@@ -130,7 +129,7 @@ Transform:
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1689627663639590}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalPosition: {x: 0, y: 9.42, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:
- {fileID: 4415104517465482}
@@ -139,26 +138,6 @@ Transform:
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!50 &50022655303262748
Rigidbody2D:
serializedVersion: 4
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1689627663639590}
m_BodyType: 0
m_Simulated: 1
m_UseFullKinematicContacts: 0
m_UseAutoMass: 0
m_Mass: 1
m_LinearDrag: 0
m_AngularDrag: 0.05
m_GravityScale: 1
m_Material: {fileID: 0}
m_Interpolate: 0
m_SleepingMode: 1
m_CollisionDetection: 0
m_Constraints: 0
--- !u!50 &50427200981694222
Rigidbody2D:
serializedVersion: 4

View File

@@ -207,7 +207,7 @@ Prefab:
objectReference: {fileID: 0}
- target: {fileID: 4937824842681064, guid: 6ffa9e4f03b5e9e48963b7243568dc62, type: 2}
propertyPath: m_LocalPosition.y
value: 0
value: 9.42
objectReference: {fileID: 0}
- target: {fileID: 4937824842681064, guid: 6ffa9e4f03b5e9e48963b7243568dc62, type: 2}
propertyPath: m_LocalPosition.z
@@ -233,18 +233,7 @@ Prefab:
propertyPath: m_RootOrder
value: 2
objectReference: {fileID: 0}
- target: {fileID: 50022655303262748, guid: 6ffa9e4f03b5e9e48963b7243568dc62,
type: 2}
propertyPath: m_Simulated
value: 1
objectReference: {fileID: 0}
- target: {fileID: 50022655303262748, guid: 6ffa9e4f03b5e9e48963b7243568dc62,
type: 2}
propertyPath: m_BodyType
value: 1
objectReference: {fileID: 0}
m_RemovedComponents:
- {fileID: 50022655303262748, guid: 6ffa9e4f03b5e9e48963b7243568dc62, type: 2}
m_RemovedComponents: []
m_ParentPrefab: {fileID: 100100000, guid: 6ffa9e4f03b5e9e48963b7243568dc62, type: 2}
m_IsPrefabParent: 0
--- !u!1 &1138483822

View File

@@ -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>();