/// <summary> /// Increase or decrease based on given direction. /// </summary> /// <param name="Direction"></param> protected void Change(UpDownDirection Direction) { if (Direction == UpDownDirection.Up) { if (CanIncrease()) { Increase(); } else if (DirectionalChange == DirectionalNavigation.Circular) { SinkValue(); //Value = Minimum; } } else if (Direction == UpDownDirection.Down) { if (CanDecrease()) { Decrease(); } else if (DirectionalChange == DirectionalNavigation.Circular) { RiseValue(); //Value = Maximum; } } }
/// <summary> /// Increase or decrease based on given direction. /// </summary> /// <param name="Direction"></param> protected void Change(UpDownDirection Direction) { if (Direction == UpDownDirection.Up && CanIncrease()) { Increase(); } else if (Direction == UpDownDirection.Down && CanDecrease()) { Decrease(); } }
public void InstantiateTunnel() { // Change the position of the builder to the position, where the object has to be instantiated, using NextTunnelInfo.pivotlength Vector3 OldPosition = transform.localPosition; Vector3 NewPosition = new Vector3(0, 0, 0); if (directioncounterUpDown == 1 && directioncounterLeftRight == 0 || directioncounterUpDown == 1 && directioncounterLeftRight == -1 && LastTunnelInfo.goingUp || directioncounterUpDown == 1 && directioncounterLeftRight == 1 && LastTunnelInfo.goingUp) { //FACING UP NewPosition = new Vector3(0, NextTunnelInfo.pivotlength, 0); transform.Translate(NewPosition, Space.World); } else if (directioncounterUpDown == -1 && directioncounterLeftRight == 0 || directioncounterUpDown == -1 && directioncounterLeftRight == -1 && LastTunnelInfo.goingDown || directioncounterUpDown == -1 && directioncounterLeftRight == 1 && LastTunnelInfo.goingDown) { //FACING DOWN NewPosition = new Vector3(0, -NextTunnelInfo.pivotlength, 0); transform.Translate(NewPosition, Space.World); } else if (directioncounterUpDown == 1 && directioncounterLeftRight == 1 && LastTunnelInfo.goingRight || directioncounterUpDown == -1 && directioncounterLeftRight == 1 && LastTunnelInfo.goingRight || directioncounterLeftRight == 1 && directioncounterUpDown == 0 || NTunnel.TunnelDir == ObjectInformation.TunnelDirection.UpRight || NTunnel.TunnelDir == ObjectInformation.TunnelDirection.DownRight) { //FACING RIGHT NewPosition = new Vector3(NextTunnelInfo.pivotlength, 0, 0); transform.Translate(NewPosition, Space.World); } else if (directioncounterUpDown == 1 && directioncounterLeftRight == -1 && LastTunnelInfo.goingLeft || directioncounterUpDown == -1 && directioncounterLeftRight == -1 && LastTunnelInfo.goingLeft || directioncounterLeftRight == -1 && directioncounterUpDown == 0 || NTunnel.TunnelDir == ObjectInformation.TunnelDirection.UpLeft || NTunnel.TunnelDir == ObjectInformation.TunnelDirection.DownLeft) { //FACING LEFT NewPosition = new Vector3(-NextTunnelInfo.pivotlength, 0, 0); transform.Translate(NewPosition, Space.World); } else { //FACING FORWARD NewPosition = new Vector3(0, 0, NextTunnelInfo.pivotlength); transform.Translate(NewPosition, Space.World); } // Instantiating the TunnelSystem if (NextTunnel != 0) { NewTunnel = Instantiate(TunnelSystems[NextTunnel], transform.localPosition, transform.localRotation); LastTunnel = NextTunnel; LastTunnelInfo = TunnelSystems[LastTunnel].GetComponent <ObjectInformation>(); } else if (NextTunnel == 0 && DefaultTunnelInAdvance == 0) { int i = Random.Range(0, DogeTunnelSystems.Length); NewTunnel = Instantiate(DogeTunnelSystems[i], transform.localPosition, transform.localRotation); LastTunnel = NextTunnel; LastTunnelInfo = DogeTunnelSystems[i].GetComponent <ObjectInformation>(); } NextTunnelChosen = false; // Revert the positionchange to prepare for the next tunnel transform.Translate(-NewPosition, Space.World); // If the TunnelSystem is changing the general direction, change the Direction-enum and rotate the object if (LastTunnelInfo.goingRight) { directioncounterLeftRight++; if (d == Direction.Zero) { d = Direction.Ninety; } else if (d == Direction.Ninety) { d = Direction.OneEighty; } else if (d == Direction.OneEighty) { d = Direction.TwoSeventy; } else if (d == Direction.TwoSeventy) { d = Direction.Zero; } transform.Rotate(0, 90, 0); } if (LastTunnelInfo.goingLeft) { directioncounterLeftRight--; if (d == Direction.Zero) { d = Direction.TwoSeventy; } else if (d == Direction.Ninety) { d = Direction.Zero; } else if (d == Direction.OneEighty) { d = Direction.Ninety; } else if (d == Direction.TwoSeventy) { d = Direction.OneEighty; } transform.Rotate(0, -90, 0); } if (LastTunnelInfo.goingUp) { directioncounterUpDown++; if (dUpDown == UpDownDirection.Zero) { dUpDown = UpDownDirection.Ninety; } else if (dUpDown == UpDownDirection.MinusNinety) { dUpDown = UpDownDirection.Zero; } transform.Rotate(-90, 0, 0); } if (LastTunnelInfo.goingDown) { directioncounterUpDown--; if (dUpDown == UpDownDirection.Zero) { dUpDown = UpDownDirection.MinusNinety; } else if (dUpDown == UpDownDirection.Ninety) { dUpDown = UpDownDirection.Zero; } transform.Rotate(90, 0, 0); } // TunnelDirection for rotationchange // Up NTunnel = NewTunnel.GetComponent <ObjectInformation>(); if (NTunnel.NoDirectionalChange) { if (directioncounterUpDown == 1 && directioncounterLeftRight == 0) { NTunnel.TunnelDir = ObjectInformation.TunnelDirection.Up; currentHeight++; } // UpRight else if (directioncounterUpDown == 1 && directioncounterLeftRight == 1) { currentLeftRight++; NTunnel.TunnelDir = ObjectInformation.TunnelDirection.UpRight; } // UpLeft else if (directioncounterUpDown == 1 && directioncounterLeftRight == -1) { currentLeftRight--; NTunnel.TunnelDir = ObjectInformation.TunnelDirection.UpLeft; } // Down else if (directioncounterUpDown == -1 && directioncounterLeftRight == 0) { NTunnel.TunnelDir = ObjectInformation.TunnelDirection.Down; currentHeight--; } // DownRight else if (directioncounterUpDown == -1 && directioncounterLeftRight == 1) { currentLeftRight++; NTunnel.TunnelDir = ObjectInformation.TunnelDirection.DownRight; } // DownLeft else if (directioncounterUpDown == -1 && directioncounterLeftRight == -1) { currentLeftRight--; NTunnel.TunnelDir = ObjectInformation.TunnelDirection.DownLeft; } // Right else if (directioncounterLeftRight == 1 && directioncounterUpDown == 0) { currentLeftRight++; NTunnel.TunnelDir = ObjectInformation.TunnelDirection.Right; } // Left else if (directioncounterLeftRight == -1 && directioncounterUpDown == 0) { currentLeftRight--; NTunnel.TunnelDir = ObjectInformation.TunnelDirection.Left; } // Forward else { NTunnel.TunnelDir = ObjectInformation.TunnelDirection.Forward; } } // Use the Environment object as parent for instantiated tunnelsystems NewTunnel.transform.parent = Environment.transform; timesbuilt += 1; NTunnel.TunnelNumber = timesbuilt; UpdateBuilderPosition(); ChooseNextTunnel(); }