title: How to Swap "rigid body" with add force in 8 direction using C#?
body: <p>I am beginner of C# unity. I was searching the solution to swap cube with <code>add force</code> in <code>8 direction</code>, but I could not find anything. I am really confused that how can I do this. Someone please guide me in this regard. Any code example or tutorial for solving the problem will be appreciated.</p>
  
  <p>Thanks in advance.
  Here is my code:</p>
  
  <pre><code>using UnityEngine;
  using System.Collections;
  
  public class Swaping1 : MonoBehaviour {
      int swipeIndex = -1; //index of first detected swipe to prevent multiple swipes
      public Vector2 startPos;  //starting position of touch
      public float minSwipeDist;
  
      public float UpSwape;
      public float DownSwape;
      public float LeftSwape;
      public float RightSwape;
      public GUIButtons GUIButtonsObj;
  
      // Use this for initialization
      void Start () {
          GUIButtonsObj=GetComponent&lt;GUIButtons&gt;();
      }
  
      public void swipe()
      {
          for (int i = 0; i &lt; Input.touchCount; i++) {
              Touch touch = Input.touches [i];
              switch (touch.phase) {
              case TouchPhase.Began:
                  if (swipeIndex == -1) {
                      swipeIndex = i;
                      startPos = touch.position;
                  }
                  break;
              case TouchPhase.Moved:
                  if (i != swipeIndex)
                      break;
                  Vector2 direction = touch.position - startPos;
                  //vertical swipe
                  if (Mathf.Abs (direction.x) &lt; Mathf.Abs (direction.y)) {
                      //swipe up
                      if ((touch.position.y - startPos.y) &gt; minSwipeDist) {
                          //GUIButtonsObj.UpButton();
                          //transform.Translate(0f, UpSwape, 0f);
                          swipeIndex = -1;
                      }
                      //swipe down
                      else if ((touch.position.y - startPos.y) &lt; -minSwipeDist) {
                          //transform.Translate(0f, -DownSwape, 0f);
                          //GUIButtonsObj.DownButton();
                          swipeIndex = -1;
                      }
                  }
                  //horizontal swipe
                  else {
                      //swipe right
                      if ((touch.position.x - startPos.x) &lt; -minSwipeDist) {
                          //transform.Translate(-RightSwape, 0f, 0f);
                          GUIButtonsObj.LeftButton();
                          swipeIndex = -1;
                      }
                      //swipe left
                      else if ((touch.position.x - startPos.x) &gt; minSwipeDist) {
                          //  transform.Translate(LeftSwape, 0f, 0f);
                          GUIButtonsObj.RightButton();
                          swipeIndex = -1;
                      }
                  }
                  break;
              }
          }
      }
  
      // Update is called once per frame
      void Update () 
      {
          swipe ();
      }
  }
  </code></pre>