Advertisement
moinularif

getDirection

Jun 24th, 2015
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.79 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class vector3Mapping : MonoBehaviour {
  5.  
  6.  
  7.     public static Vector3 leftPosition;
  8.     public static Vector3 rightPosition;
  9.  
  10.     public float directionValue;
  11.  
  12.     // Use this for initialization
  13.     void Start () {
  14.  
  15.         leftPosition = rightPosition = new Vector3(0f,0f,0f);
  16.         directionValue = 0;
  17.    
  18.    
  19.     }
  20.    
  21.     // Update is called once per frame
  22.     void Update () {
  23.  
  24.         GetDirection();
  25.  
  26.  
  27.    
  28.     }
  29.  
  30.     public float GetDirection ()
  31.     {
  32.         if (leftPosition.z > rightPosition.z)
  33.         {
  34.             Debug.Log("Go to Right");
  35.  
  36.             if (leftPosition.z > range1)
  37.             {
  38.                 directionValue = 0f;
  39.             }
  40.  
  41.             else if (leftPosition.z >= range2 && leftPosition.z < range3)
  42.             {
  43.                 directionValue = 0.25f;
  44.             }
  45.             else if (leftPosition.z >= range3 && leftPosition.z < range4)
  46.             {
  47.                 directionValue = 0.75f;
  48.             }
  49.             else if (leftPosition.z >= range4 )
  50.             {
  51.                 directionValue = 1.0f;
  52.             }
  53.  
  54.         }
  55.  
  56.         else
  57.         {
  58.             Debug.Log("Go to Left");
  59.  
  60.             if (rightPosition.z > range1)
  61.             {
  62.                 directionValue = 0f;
  63.             }
  64.  
  65.             else if (rightPosition.z >= range2 && rightPosition.z < range3)
  66.             {
  67.                 directionValue =- 0.25f;
  68.             }
  69.             else if (rightPosition.z >= range3 && rightPosition.z < range4)
  70.             {
  71.                 directionValue = -0.75f;
  72.             }
  73.             else if (rightPosition.z >= range4 && rightPosition.z < range5)
  74.             {
  75.                 directionValue =- 1.0f;
  76.             }
  77.  
  78.  
  79.         return directionValue;
  80.         }
  81.     }
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement