Commit 5ddb77679c900698960d526db069d04f939dc290

Authored by Danish Siddiqui
1 parent c1d61a206b
Exists in master

Updated script to follow X and Y axis as well

Showing 1 changed file with 38 additions and 30 deletions Side-by-side Diff

Assets/_Scripts/FollowTarget.cs
... ... @@ -5,6 +5,7 @@
5 5  
6 6 public GameObject Target;
7 7  
  8 + public float DistanceX;
8 9 public float DistanceY;
9 10 public float DistanceZ;
10 11  
... ... @@ -14,7 +15,7 @@
14 15  
15 16 // Use this for initialization
16 17 void Start () {
17   - SwipeController.SwipeEvent += Swipe;
  18 +// SwipeController.SwipeEvent += Swipe;
18 19 }
19 20  
20 21 // Update is called once per frame
21 22  
22 23  
23 24  
24 25  
25 26  
... ... @@ -23,46 +24,53 @@
23 24 if(FollowZ){
24 25 float distance = Target.transform.position.z - transform.position.z;
25 26 if(distance != DistanceZ){
26   - transform.position = new Vector3(Target.transform.position.x, transform.position.y, Target.transform.position.z - DistanceZ);
  27 + transform.position = new Vector3(transform.position.x, transform.position.y, Target.transform.position.z + DistanceZ);
27 28 }
28 29 }
29 30  
30 31 if(FollowY){
31 32 float distance = transform.position.y - Target.transform.position.y;
32 33 if(distance != DistanceY){
33   - transform.position = new Vector3(Target.transform.position.x, DistanceY + Target.transform.position.y, transform.position.z);
  34 + transform.position = new Vector3(transform.position.x, DistanceY + Target.transform.position.y, transform.position.z);
34 35 }
35 36 }
36   - }
37 37  
38   - // -1 for left
39   - // 1 fpr right
40   - void Swipe(SwipeController.DIRECTION direction){
41   -
42   - if(!FollowX)
43   - return;
44   -
45   - switch(direction){
46   - case SwipeController.DIRECTION.LEFT:
47   - StartCoroutine(MoveSideways(-1));
48   -
49   - break;
50   - case SwipeController.DIRECTION.RIGHT:
51   - StartCoroutine(MoveSideways(1));
52   - break;
  38 + if(FollowX){
  39 + float distance = transform.position.x - Target.transform.position.x;
  40 + if(distance != DistanceX){
  41 + transform.position = new Vector3(DistanceX + Target.transform.position.x, DistanceY + Target.transform.position.y, transform.position.z);
  42 + }
53 43 }
54   -
55 44 }
56 45  
57   - IEnumerator MoveSideways(int direction){
58   -
59   - float distance = 0;
60   - while(distance < 2){
61   - transform.Translate(new Vector3(0.35f * direction,0,0));
62   - distance += 0.35f;
63   - yield return new WaitForEndOfFrame();
64   - }
65   -
66   - }
  46 +// // -1 for left
  47 +// // 1 fpr right
  48 +// void Swipe(SwipeController.DIRECTION direction){
  49 +//
  50 +// if(!FollowX)
  51 +// return;
  52 +//
  53 +// switch(direction){
  54 +// case SwipeController.DIRECTION.LEFT:
  55 +// StartCoroutine(MoveSideways(-1));
  56 +//
  57 +// break;
  58 +// case SwipeController.DIRECTION.RIGHT:
  59 +// StartCoroutine(MoveSideways(1));
  60 +// break;
  61 +// }
  62 +//
  63 +// }
  64 +//
  65 +// IEnumerator MoveSideways(int direction){
  66 +//
  67 +// float distance = 0;
  68 +// while(distance < 2){
  69 +// transform.Translate(new Vector3(0.35f * direction,0,0));
  70 +// distance += 0.35f;
  71 +// yield return new WaitForEndOfFrame();
  72 +// }
  73 +//
  74 +// }
67 75 }