# Cut a 2D model

Hello everyone,
I am relatively new to unity, and, although I have done some research, none is useful, or presented in a way that I can comprehend. I want to do something like this:

Could someone show and explain implemented code? Thank you! By the way, I work in IOS, so if the code could be easily converted to touch, I would be grateful. I can convert.

The technique is called CSG (Constructive solid geometry) and it isn’t trivial. There are references online that explain how it’s done, but you’ll have to implement it yourself in Unity. Mesh API would be the place to start. If you’re new to Unity or programming as you claim, than you’re probably better off using an existing asset on the store:

Turbo Slicer

Sprite Slicer

here is a sample script (javascript):

FingerLine.js

#pragma strict

@script RequireComponent(LineRenderer)

var lineRenderer : LineRenderer;
var myPoints : Vector3;

function Start () {
lineRenderer = GetComponent(LineRenderer);
lineRenderer.SetWidth(0.2,0.2);
}

function Update () {

`````` if(myPoints){
lineRenderer.SetVertexCount(myPoints.Length);
for(var i = 0;i<myPoints.Length;i++){
lineRenderer.SetPosition(i,myPoints*);*
``````

}
}
else
lineRenderer.SetVertexCount(0);

if(Input.touchCount > 0){
if(Input.touches[0].phase == TouchPhase.Began)
}
else{
CancelInvoke();
myPoints = null;
}
}

var tempPoints : Vector3[];

if(!myPoints)
tempPoints = new Vector3[1];
else{
tempPoints = new Vector3[myPoints.Length+1];

for(var j = 0; j < myPoints.Length; j++)
tempPoints[j] = myPoints[j];
}
var tempPos : Vector3 = Input.mousePosition;
tempPos.z = 10;

tempPoints[j] = Camera.main.ScreenToWorldPoint(tempPos);
myPoints = new Vector3[tempPoints.Length];
myPoints = tempPoints;
}
this pretty much works on its own, just attach to the camera of a new scene and build…
Enjoy!