I have this chunk of code, where I am trying to implement multitouch, but it isnt working.
Can someone please help me with it ?
function Update()
{
if(startTheTimer)
{
startGameTimer += Time.deltaTime;
}
if(startGameTimer > startCountDownLength)
{
globalGameStart = true;
shootEnable = true;
startTheTimer = false;
startGameTimer = 0;
}
var IgnoreLayer = 8;
var IgnoreMask : LayerMask = 1<<IgnoreLayer;
if(Input.touchCount > 0)
{
for (var i = 0; i < Input.touchCount; ++i)
{
var touch = Input.touches[i];
var ray = Camera.main.ScreenPointToRay (touch.position);
var hit: RaycastHit;
if (Physics.Raycast (ray, hit,100,IgnoreMask))
{
myObject = hit.transform.gameObject;
myObjPos = myObject.transform.position;
if(myObject.tag == "SphereBlue")
{
objBit = 0;
}else
{
if(myObject.tag == "SphereYellow")
{
objBit = 1;
}
}
Onhit = true;
}
if(Onhit)
{
if(touch.phase == TouchPhase.Began)
{
touchStart= touch.position;
}else
{
if(touch.phase == TouchPhase.Moved)
{
if (Mathf.Abs(touch.position.y - touchStart.y) < comfortZone)
{
couldbeswipe = false;
}
else
{
couldbeswipe = true;
}
}
if(touch.phase == TouchPhase.Stationary)
{
if (Mathf.Abs(touch.position.y - touchStart.y) < comfortZone)
{
couldbeswipe = false;
}
}
if(touch.phase == TouchPhase.Ended)
{
var swipeDist = (touch.position - touchStart).magnitude;
if (couldbeswipe swipeDist > comfortZone)
{
touchEnd = touch.position;
if(OnPlatform(touchEnd))
{
var section = QuadSec(touchEnd);
if(mapBit[section.x,section.y] == 0)
{
var positionToMove = returnPosition(section);
Onhit = false;
var newOb = Instantiate(objs[objBit],myObject.transform.position,myObject.transform.rotation);
var project : Project = newOb.GetComponent(Project);
project.project = true;
project.end = positionToMove ;
Destroy(myObject);
mapBit[section.x,section.y] = 1;
}
}else
{
var sectionO = outSection(touchEnd);
var positionToMoveO = outPosition(sectionO);
Onhit = false;
var newObo = Instantiate(objs[objBit],myObject.transform.position,myObject.transform.rotation);
var project2 : Project = newObo.GetComponent(Project);
project2.project = true;
project2.end = positionToMoveO ;
Destroy(myObject);
}
}
}
}
}
}
}
}