Skip to content

Instantly share code, notes, and snippets.

@Kwentar
Last active February 2, 2016 13:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Kwentar/61e3d8a93b73da820815 to your computer and use it in GitHub Desktop.
Save Kwentar/61e3d8a93b73da820815 to your computer and use it in GitHub Desktop.
using UnityEngine;
using System.Collections;
public class MainSphereScript : MonoBehaviour {
bool moving = false;
int countMovingFrames = 100; //время движения в кадрах
int currentCountFrames = 0;
bool reverse = false; //флаг прямого/обратного движения
void Start ()
{
KinectManagerScript.OnSwipeUpDown += new KinectManagerScript.SimpleEvent(KinectManagerScript_OnSwipeUpDown);
}
void KinectManagerScript_OnSwipeUpDown()
{
Debug.Log("upDown From listener");
if (!moving)
{
moving = true;
reverse = false;
currentCountFrames = 0;
}
}
void Update ()
{
if (moving)
{
currentCountFrames++;
if (currentCountFrames >= countMovingFrames)
{
if (!reverse)
{
reverse = true;
currentCountFrames = 0;
}
else
{
moving = false;
}
}
if(!reverse)
transform.Translate(-2* Vector3.up * Time.deltaTime); //прямой ход
else
transform.Translate(2* Vector3.up * Time.deltaTime); // обратный ход
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment