c# - How to place objects by swipe your finger across the screen? -


using this tutorial can place objects on surface finger tap.

how can change script place objects while swiping finger across screen, placing objects "painting" area should placed?

here script placing tutorial:

using unityengine; using system.collections;  public class kittyuicontroller : monobehaviour {     public gameobject m_kitten;     private tangopointcloud m_pointcloud;      void start()     {         m_pointcloud = findobjectoftype<tangopointcloud>();     }      void update ()     {         if (input.touchcount == 1)         {             // trigger place kitten function when single touch ended.             touch t = input.gettouch(0);             if (t.phase == touchphase.ended)             {                 placekitten(t.position);             }         }     }      void placekitten(vector2 touchposition)     {         // find plane.         camera cam = camera.main;         vector3 planecenter;         plane plane;         if (!m_pointcloud.findplane(cam, touchposition, out planecenter, out plane))         {             debug.log("cannot find plane.");             return;         }          // place kitten on surface, , make face camera.         if (vector3.angle(plane.normal, vector3.up) < 30.0f)         {             vector3 = plane.normal;             vector3 right = vector3.cross(plane.normal, cam.transform.forward).normalized;             vector3 forward = vector3.cross(right, plane.normal).normalized;             instantiate(m_kitten, planecenter, quaternion.lookrotation(forward, up));         }         else         {             debug.log("surface steep kitten stand on.");         }     } } 

instead of spawning kitten when touchphase ends, can spawn them whenever touch moves: touchphase.moved. warned - spawn lot of kittens while drag since being checked every frame while in update() method. consider adding time delay, or spawning after finger moves distance.

    void update ()     {         if (input.touchcount == 1)         {             // trigger place kitten function when single touch moves.             touch t = input.gettouch(0);             if (t.phase == touchphase.moved)             {                 placekitten(t.position);             }         }     } 

a distance check implemented so:

float vector3 oldpos;  void update () {     if (input.touchcount == 1)     {         touch t = input.gettouch(0);         if (t.phase == touchphase.began)         {             oldpos = t.position; //get initial touch position         }         if (t.phase == touchphase.moved)         {             // check if distance between stored position , current touch position greater "2"             if (mathf.abs(vector3.distance(oldpos, t.position)) > 2f)             {                 placekitten(t.position);                 oldpos = t.position; // store position next distance check             }         }     } } 

Comments

Popular posts from this blog

javascript - Create a stacked percentage column -

Optimising Firebase database by automatically overwriting data -

javascript - Angular UI-Grid customTemplate directive causing rows to load slowly/? -