- Home /
This post has been wikified, any user with enough reputation can edit it.
Question by
shygeek · Mar 15, 2014 at 05:34 AM ·
gameobjectraycastswipe
Swipe individual gameobjects in a scene
Hello ! I've a scene in which I need to swipe on individual gameobjects to perform an in built animation. I think I'll have to use raycast function for this. But I'm really new to coding. Can someone help ?
My present swipe code for up/down swipe(detects swipe on the whole screen instead of individual gameobject)
var finid:int=-1;
var uptest:boolean=true;
var downtest:boolean=true;
var StartPos:Vector2;
var dis:float=20.0;
var top : GameObject;
var front : GameObject;
function Update ()
{
for(var touch:Touch in Input.touches)
{
var pos = touch.position;
if (touch.phase == TouchPhase.Began && finid == -1)
{
finid = touch.fingerId;
StartPos = pos;
}
else if (touch.fingerId == finid)
{
var delta = pos - StartPos;
if (touch.phase == TouchPhase.Moved && delta.magnitude > dis)
{
finid = -1;
if (Mathf.Abs(delta.x) > Mathf.Abs(delta.y))
{
//
}
else
{
if (uptest && delta.y > 0)
{
Debug.Log("up");
top.SetActive(true);
}
else if (downtest && delta.y < 0)
{
front.SetActive(true);
}
}
}
else if (touch.phase == TouchPhase.Canceled || touch.phase == TouchPhase.Ended)
finid = -1;
}
}
}
Comment