c# - Rotated an model in Unity? -
i bulid project when if :
- user swipe left model model should rotated left.
- user swipe right model model should rotated rifgt.
- user swipe down model model should rotated down.
- user swipe model model should rotated up.
what did till :
add 3d model in front of camera. made c# file.
now need basic code can make rotated on swipe. how run project in phone.
here basic code come after build first c# file of model :
void start() } void update(){} }
you can use rotate
achieve rotation of model (see rotate documentation)
then use this example detect swipe in each direction.
you can try this:
var speed = 0.1; function update () { if (input.touchcount > 0 && input.gettouch(0).phase == touchphase.moved) { // movement of finger since last frame var touchdeltaposition = input.gettouch(0).deltaposition; // move object across xy plane var rotationvector = new vector3(touchdeltaposition.x, touchdeltaposition.y, 0); transform.rotate(rotationvector * speed, space.world); } }
Comments
Post a Comment