I can do as I hit between line renderer, I think several lines drawing with the touch but I need the intersection between the lines that make or detect collision with a hit
this is my code:
var thePen: GameObject;
private var currentPen: GameObject;
var linePoints: ArrayList = new ArrayList();
private var lineCount:int = 0;
var lastPos: Vector3 = Vector3.one * float.MaxValue;
var startWidth: float = 0.2f;
var endWidth: float = 0.2f;
var threshold: float = 0.001f;
function Start () {
}
function Update ()
{
if( (Input.touchCount > 0 Input.GetTouch(0).phase == TouchPhase.Began) || Input.GetMouseButtonDown(0))
{
var mousePos: Vector3 = Input.mousePosition;
mousePos.z = 1;
var mouseWorld: Vector3 = Camera.main.ScreenToWorldPoint(mousePos);
currentPen = Instantiate(thePen, thePen.transform.position,thePen.transform.rotation);
linePoints = new ArrayList();
lineCount = 0;
lastPos = mouseWorld;
linePoints.Add(mouseWorld);
UpdateLine();
var hit : RaycastHit;
var ray = Camera.main.ScreenPointToRay (mousePos);
if (!Physics.Raycast (ray, hit, 10000))
return;
//we've hit a sphere
if(hit.transform.gameObject.name == "ball")
{
Debug.Log("Hit the ball");
}
if(hit.transform.gameObject.name == "capsule")
{
Debug.Log("Hit the capsule");
}
}
else if(((Input.touchCount > 0 Input.GetTouch(0).phase == TouchPhase.Moved) || Input.GetMouseButton(0)))
{
var mousePos2: Vector3 = Input.mousePosition;
mousePos2.z = 1;
var mouseWorld2: Vector3 = Camera.main.ScreenToWorldPoint(mousePos2);
var dist: float = Vector3.Distance(lastPos, mouseWorld2);
if(dist <= threshold)
return;
lastPos = mouseWorld2;
if(linePoints == null)
linePoints = new ArrayList();
linePoints.Add(mouseWorld2);
UpdateLine();
var hit1 : RaycastHit;
var ray1 = Camera.main.ScreenPointToRay (mousePos2);
if (!Physics.Raycast (ray1, hit1, 10000))
return;
//we've hit a sphere
if(hit1.transform.gameObject.name == "ball")
{
Debug.Log("Hit the ball");
}
if(hit1.transform.gameObject.name == "capsule")
{
Debug.Log("Hit the capsule");
}
if(hit1.transform.gameObject.name == "hit the line")
{
Debug.Log("Hit the line");
}
}
else if((Input.touchCount > 0 Input.GetTouch(0).phase == TouchPhase.Ended) || Input.GetMouseButtonUp(0))
{
}
}
function UpdateLine()
{
var mousePos3: Vector3 = Input.mousePosition;
//currentPen = Instantiate(thePen, thePen.transform.position,thePen.transform.rotation);
currentPen.GetComponent(LineRenderer).SetWidth(0.2f, 0.2f);
currentPen.GetComponent(LineRenderer).SetVertexCount(linePoints.Count);
for(var i = lineCount; i < linePoints.Count; i++)
{
currentPen.GetComponent(LineRenderer).SetPosition(i, linePoints[i]);
}
currentPen.GetComponent(LineRenderer).materials[0].mainTextureScale = new Vector2 (linePoints.Count-1,1);
currentPen.GetComponent(LineRenderer).name = "Swipe";
lineCount = linePoints.Count;
var hit2 : RaycastHit;
var ray2 = Camera.main.ScreenPointToRay (mousePos3);
if (Physics.Raycast (ray2, hit2, 10000))
Debug.Log("Hit the line");
return;
//we've hit a sphere
if(hit2.transform.gameObject.tag == lineCount)
{
Debug.Log("Hit the line");
}
}
I need to detect any ideas?
sorry for my English