Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class TickerbombControl : MonoBehaviour {
- public bool SetPlayer;
- public PlayerScript PlayerAccess; // This is really important for being able to determin if the game started yet.
- public bool IsPlaying;
- public enum Clock { Clockwise, Counterclockwise }
- public Clock ClockType;
- public bool SetAnimation;
- // There are two ways the tickerbomb detects walls.
- // * Initial is for detecting our initial position.
- public GameObject InitialGameObject; // So we can disable it when we're done.
- public ColliderTester InitialAccess;
- // * Clinging is for riding on the outside of walls.
- public ColliderTester ClingingAccess;
- // * Forward is for detecting when we hit a wall.
- public ColliderTester ForwardAccess;
- // This is for detecting if we hit ticker bricks we're clinging to
- public ColliderTester ClingTickerBrick;
- public GameObject ClingDetectBrickClockwise;
- public GameObject ClingDetectBrickCounterClockwise;
- public bool Initialize; // This is used because we "Start" is called before we know our edge.
- private bool FirstCheck; // This is so we know we set our initial movement.
- private bool TopEdge;
- private bool LeftEdge;
- private bool BottomEdge;
- private bool RightEdge;
- public enum Movement { NotSet, MovingLeft, MovingDown, MovingRight, MovingUp, }
- public Movement MovementPath;
- public bool ForwardHit;
- public float speed;
- private SpeedControl.SpeedDirections Speed;
- public enum ClingAngles { Bottom, Left, Top, Right }
- public ClingAngles ClingAngle;
- public bool ClingHitting;
- public bool ResetForward;
- public bool ResetCling;
- public bool EXPLODE;
- public Color NotTriggered;
- public Color Triggered;
- public Renderer LightTrigger;
- public GameObject TickerExplodeTrigger;
- public Animation RotatingAnimation;
- public GameObject ExplodeEffect;
- private float timeExplode;
- public float ExplodeTime; // Set time to explode.
- //-------------------------//
- //---[[ CLOCKWISE ]]---//
- //-------------------------//
- public void SpinningClockwise()
- {
- // Sets the animation [*]
- if (!SetAnimation)
- {
- ClingDetectBrickClockwise.SetActive(true);
- ClingDetectBrickCounterClockwise.SetActive(false);
- ClingTickerBrick = ClingDetectBrickClockwise.GetComponent<ColliderTester>();
- RotatingAnimation.Play("Spinning Spikes_Clockwise");
- SetAnimation = true;
- }
- // Sets the clinging angle depending on which way we're moving. [**]
- switch (MovementPath)
- {
- case Movement.MovingDown:
- ClingAngle = ClingAngles.Left;
- break;
- case Movement.MovingLeft:
- ClingAngle = ClingAngles.Top;
- break;
- case Movement.MovingUp:
- ClingAngle = ClingAngles.Right;
- break;
- case Movement.MovingRight:
- ClingAngle = ClingAngles.Bottom;
- break;
- }
- // Set our initial movement path after we're sure it's settled in. [***]
- if (Initialize & !FirstCheck)
- {
- if (TopEdge)
- MovementPath = Movement.MovingLeft;
- else if (LeftEdge)
- MovementPath = Movement.MovingDown;
- else if (BottomEdge)
- MovementPath = Movement.MovingRight;
- else if (RightEdge)
- MovementPath = Movement.MovingUp;
- else
- MovementPath = Movement.MovingRight;
- ClingHitting = true;
- InitialGameObject.SetActive(false);
- FirstCheck = true;
- }
- CheckForward();
- CheckCling();
- }
- //-------------------------//
- //-[[ COUNTER CLOCKWISE ]]-//
- //-------------------------//
- public void SpinningCounterClockwise()
- {
- // Sets the animation [*]
- if (!SetAnimation)
- {
- ClingDetectBrickCounterClockwise.SetActive(true);
- ClingDetectBrickClockwise.SetActive(false);
- ClingTickerBrick = ClingDetectBrickCounterClockwise.GetComponent<ColliderTester>();
- RotatingAnimation.Play("Spinning Spikes_CounterClockwise");
- SetAnimation = true;
- }
- // Sets the clinging angle depending on which way we're moving. [**]
- switch (MovementPath)
- {
- case Movement.MovingDown:
- ClingAngle = ClingAngles.Right;
- break;
- case Movement.MovingLeft:
- ClingAngle = ClingAngles.Bottom;
- break;
- case Movement.MovingUp:
- ClingAngle = ClingAngles.Left;
- break;
- case Movement.MovingRight:
- ClingAngle = ClingAngles.Top;
- break;
- }
- // Set our initial movement path after we're sure it's settled in. [***]
- if (Initialize & !FirstCheck)
- {
- if (TopEdge)
- MovementPath = Movement.MovingRight;
- else if (LeftEdge)
- MovementPath = Movement.MovingUp;
- else if (BottomEdge)
- MovementPath = Movement.MovingLeft;
- else if (RightEdge)
- MovementPath = Movement.MovingUp;
- else
- MovementPath = Movement.MovingLeft;
- ClingHitting = true;
- InitialGameObject.SetActive(false);
- FirstCheck = true;
- }
- CheckForward();
- CheckCling();
- }
- public void CheckEdges()
- {
- TopEdge = InitialAccess.HitTop;
- BottomEdge = InitialAccess.HitBottom;
- LeftEdge = InitialAccess.HitLeft;
- RightEdge = InitialAccess.HitRight;
- }
- public void SetSensors()
- {
- switch (ClingAngle)
- {
- case ClingAngles.Bottom:
- ClingingAccess.transform.rotation = RotationalShorthand.bottom;
- // Set forward sensor
- if (ClockType == Clock.Clockwise)
- ForwardAccess.transform.rotation = RotationalShorthand.right; // Clockwise
- else
- ForwardAccess.transform.rotation = RotationalShorthand.left; // Counter Clockwise
- break;
- case ClingAngles.Left:
- ClingingAccess.transform.rotation = RotationalShorthand.left;
- // Set forward sensor
- if (ClockType == Clock.Clockwise)
- ForwardAccess.transform.rotation = RotationalShorthand.bottom; // Clockwise
- else
- ForwardAccess.transform.rotation = RotationalShorthand.top; // Counter Clockwise
- break;
- case ClingAngles.Top:
- ClingingAccess.transform.rotation = RotationalShorthand.top;
- // Set forward sensor
- if (ClockType == Clock.Clockwise)
- ForwardAccess.transform.rotation = RotationalShorthand.left; // Clockwise
- else
- ForwardAccess.transform.rotation = RotationalShorthand.right; // Counter Clockwise
- break;
- case ClingAngles.Right:
- ClingingAccess.transform.rotation = RotationalShorthand.right;
- // Set forward sensor
- if (ClockType == Clock.Clockwise)
- ForwardAccess.transform.rotation = RotationalShorthand.top; // Clockwise
- else
- ForwardAccess.transform.rotation = RotationalShorthand.bottom; // Counter Clockwise
- break;
- }
- }
- public void CheckForward()
- {
- if (!ForwardHit)
- ResetForward = false;
- ForwardHit = ForwardAccess.HittingAnything;
- if (IsPlaying & ForwardHit & Initialize & !ResetForward)
- {
- if (ForwardAccess.CheckForTag("TickerSurface"))
- EXPLODE = true;
- switch (MovementPath)
- {
- case Movement.MovingRight:
- if (ClockType == Clock.Clockwise)
- MovementPath = Movement.MovingUp;
- else
- MovementPath = Movement.MovingDown;
- break;
- case Movement.MovingUp:
- if (ClockType == Clock.Clockwise)
- MovementPath = Movement.MovingLeft;
- else
- MovementPath = Movement.MovingRight;
- break;
- case Movement.MovingLeft:
- if (ClockType == Clock.Clockwise)
- MovementPath = Movement.MovingDown;
- else
- MovementPath = Movement.MovingUp;
- break;
- case Movement.MovingDown:
- if (ClockType == Clock.Clockwise)
- MovementPath = Movement.MovingRight;
- else
- MovementPath = Movement.MovingLeft;
- break;
- }
- ResetForward = true;
- }
- }
- public void CheckCling()
- {
- if (ClingHitting)
- ResetCling = false;
- ClingHitting = ClingingAccess.HittingAnything;
- if (IsPlaying & !ClingHitting & Initialize & !ResetCling)
- {
- switch (MovementPath)
- {
- case Movement.MovingUp:
- if (ClockType == Clock.Clockwise)
- MovementPath = Movement.MovingRight;
- else
- MovementPath = Movement.MovingLeft;
- break;
- case Movement.MovingRight:
- if (ClockType == Clock.Clockwise)
- MovementPath = Movement.MovingDown;
- else
- MovementPath = Movement.MovingUp;
- break;
- case Movement.MovingDown:
- if (ClockType == Clock.Clockwise)
- MovementPath = Movement.MovingLeft;
- else
- MovementPath = Movement.MovingRight;
- break;
- case Movement.MovingLeft:
- if (ClockType == Clock.Clockwise)
- MovementPath = Movement.MovingUp;
- else
- MovementPath = Movement.MovingDown;
- break;
- }
- ResetCling = true;
- }
- if (ClingTickerBrick.HittingAnything)
- {
- if (ClingTickerBrick.CheckForTag("TickerSurface"))
- EXPLODE = true;
- }
- }
- public void PerformMovement()
- {
- switch (MovementPath)
- {
- case Movement.MovingRight:
- transform.Translate(Speed.RightSpeed);
- break;
- case Movement.MovingUp:
- transform.Translate(Speed.UpSpeed);
- break;
- case Movement.MovingDown:
- transform.Translate(Speed.DownSpeed);
- break;
- case Movement.MovingLeft:
- transform.Translate(Speed.LeftSpeed);
- break;
- }
- }
- public void CheckExplode()
- {
- if (EXPLODE)
- {
- LightTrigger.material.SetColor("_Color", Triggered);
- Instantiate(TickerExplodeTrigger, transform.position, transform.rotation);
- timeExplode = timeExplode + Time.deltaTime;
- RotatingAnimation.Stop();
- }
- else
- {
- LightTrigger.material.SetColor("_Color", NotTriggered);
- }
- if (timeExplode > ExplodeTime)
- {
- Instantiate(ExplodeEffect, transform.position, transform.rotation);
- Destroy(gameObject);
- }
- }
- void FixedUpdate ()
- {
- if (SetPlayer)
- if (PlayerAccess != null)
- IsPlaying = !PlayerAccess.IsPaused;
- else
- print("PlayerScript Access not found on " + gameObject);
- else
- {
- PlayerAccess = GameObject.Find("Player").GetComponent<PlayerScript>();
- SetPlayer = true;
- }
- Speed = new SpeedControl.SpeedDirections(speed); // Set our quickhand
- if (!Initialize) // Don't do anything until we're initialized.
- Initialize = InitialAccess.Initialized;
- CheckExplode(); // Checks to see if it's exploding.
- CheckEdges(); // Checks the edge collisions
- SetSensors(); // Set the position of our sensors
- switch (ClockType) // Set everything in motion
- {
- case Clock.Clockwise:
- SpinningClockwise();
- break;
- case Clock.Counterclockwise:
- SpinningCounterClockwise();
- break;
- }
- if (IsPlaying & !EXPLODE)
- PerformMovement();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement