Advertisement
Guest User

Untitled

a guest
Jan 21st, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.32 KB | None | 0 0
  1. using UnityEngine;
  2.  
  3. public class PlayBoundary : MonoBehaviour {
  4.  
  5.     public float xMin;
  6.     public float xMax;
  7.     public float yMin;
  8.     public float yMax;
  9.  
  10.     private Vector3 topLeftCorner;
  11.     private Vector3 topRightCorner;
  12.     private Vector3 bottomLeftCorner;
  13.     private Vector3 bottomRightCorner;
  14.  
  15.     private void Start ()
  16.     {
  17.         //prevents wrong corner values
  18.         if (xMin > xMax)
  19.             Debug.LogError ("xMin cannot be larger than xMax");
  20.         if (yMin > yMax)
  21.             Debug.LogError ("yMin cannot be larger than yMax");
  22.     }
  23.  
  24.     private void OnDrawGizmos ()
  25.     {
  26.         //Sets values for each corner of the boundary
  27.         topLeftCorner = new Vector3 (xMin * 1.25f, yMax * 1.25f, 0f);
  28.         topRightCorner = new Vector3 (xMax * 1.25f, yMax * 1.25f, 0f);
  29.         bottomLeftCorner = new Vector3 (xMin * 1.25f, yMin * 1.25f, 0f);
  30.         bottomRightCorner = new Vector3 (xMax * 1.25f, yMin * 1.25f, 0f);
  31.  
  32.         Gizmos.color = Color.red;
  33.  
  34.         //Left line
  35.         Gizmos.DrawLine (bottomLeftCorner, topLeftCorner);
  36.         //Top line
  37.         Gizmos.DrawLine (topLeftCorner, topRightCorner);
  38.         //Right line
  39.         Gizmos.DrawLine (bottomRightCorner, topRightCorner);
  40.         //Bottom line
  41.         Gizmos.DrawLine (bottomLeftCorner, bottomRightCorner);
  42.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement