Beispiel #1
0
    public override void OnInspectorGUI()
    {
        base.OnInspectorGUI();
        EditorGUILayout.EnumPopup(thruster.direction);

        if (GUILayout.Button("Center on axis"))
        {
            Undo.RecordObject(thruster.transform, "Centering thruster");
            var rb     = thruster.GetComponentInParent <Rigidbody2D>();
            var center = rb.centerOfMass;
            Debug.Log(center);
            var newThrustPos = thruster.transform.localPosition;

            var thrustDir = thruster.CalculateThrustDir();
            if (thrustDir == Direction.N || thrustDir == Direction.S)
            {
                newThrustPos.x = center.x;
            }
            else if (thrustDir == Direction.E || thrustDir == Direction.W)
            {
                newThrustPos.y = center.y;
            }

            thruster.transform.localPosition = newThrustPos;
        }
    }