Advertisement
CassataGames

New Ticker Bombs

Mar 22nd, 2014
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.12 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class TickerbombControl : MonoBehaviour {
  5.  
  6.     public ColliderTester ColliderAccess;
  7.  
  8.     // This is used because we "Start" is called before we know our edge.
  9.     public bool Initialize;
  10.  
  11.     private bool TopEdge;
  12.     private bool LeftEdge;
  13.     private bool BottomEdge;
  14.     private bool RightEdge;
  15.    
  16.     public enum Movement { NotSet, MovingLeft, MovingDown, MovingRight, MovingUp, }
  17.     public Movement MovementPath;
  18.  
  19.     public float speed;
  20.     private SpeedControl.SpeedDirections Speed;
  21.  
  22.     void Start()
  23.     {
  24.         Speed = new SpeedControl.SpeedDirections(speed);
  25.     }
  26.     void Update ()
  27.     {
  28.         // Waiting for the Collider to tell us when it's settled in, since our initial MovementPath is based on which edge we're on.        
  29.         if (!Initialize)
  30.             Initialize = ColliderAccess.Initialized;
  31.  
  32.         TopEdge = ColliderAccess.HitTop;
  33.         BottomEdge = ColliderAccess.HitBottom;
  34.         LeftEdge = ColliderAccess.HitLeft;
  35.         RightEdge = ColliderAccess.HitRight;
  36.        
  37.         // Set our initial movement path after we're sure it's settled in.
  38.         if (!Initialize)
  39.         {
  40.             if (TopEdge)
  41.                 MovementPath = Movement.MovingLeft;
  42.             else if (LeftEdge)
  43.                 MovementPath = Movement.MovingDown;
  44.             else if (BottomEdge)
  45.                 MovementPath = Movement.MovingRight;
  46.             else if (RightEdge)
  47.                 MovementPath = Movement.MovingUp;
  48.             else
  49.                 MovementPath = Movement.MovingRight;
  50.         }
  51.        
  52.         switch (MovementPath)
  53.         {
  54.             case Movement.MovingRight:
  55.                 transform.Translate(Speed.RightSpeed);
  56.                 break;
  57.             case Movement.MovingUp:
  58.                 transform.Translate(Speed.UpSpeed);
  59.                 break;
  60.             case Movement.MovingDown:
  61.                 transform.Translate(Speed.DownSpeed);
  62.                 break;
  63.             case Movement.MovingLeft:
  64.                 transform.Translate(Speed.LeftSpeed);
  65.                 break;
  66.         }
  67.     }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement