private void OnDrawGizmos() { if (awake) { Gizmos.color = Color.cyan; Vector2 boxSize = transform.TransformVector(solid.boxCollider.size); Gizmos.DrawWireCube(start, boxSize); Gizmos.DrawWireCube(end, boxSize); Gizmos.DrawLine( start + (Vector3)(boxSize * new Vector2(-0.5f, -0.5f)), end + (Vector3)(boxSize * new Vector2(-0.5f, -0.5f)) ); Gizmos.DrawLine( start + (Vector3)(boxSize * new Vector2(-0.5f, 0.5f)), end + (Vector3)(boxSize * new Vector2(-0.5f, 0.5f)) ); Gizmos.DrawLine( start + (Vector3)(boxSize * new Vector2(0.5f, 0.5f)), end + (Vector3)(boxSize * new Vector2(0.5f, 0.5f)) ); Gizmos.DrawLine( start + (Vector3)(boxSize * new Vector2(0.5f, -0.5f)), end + (Vector3)(boxSize * new Vector2(0.5f, -0.5f)) ); } else if (transform.childCount >= 2 && GetComponent <SolidController>() != null) { SolidController solid = GetComponent <SolidController>(); if (solid.GetComponent <BoxCollider2D>() != null) { Gizmos.color = gizmoColor; Transform start = transform.GetChild(0); Transform end = transform.GetChild(1); Vector2 boxSize = transform.TransformVector(solid.GetComponent <BoxCollider2D>().size); Gizmos.DrawWireCube(start.position, boxSize); Gizmos.DrawWireCube(end.position, boxSize); Gizmos.DrawLine( start.position + (Vector3)(boxSize * new Vector2(-0.5f, -0.5f)), end.position + (Vector3)(boxSize * new Vector2(-0.5f, -0.5f)) ); Gizmos.DrawLine( start.position + (Vector3)(boxSize * new Vector2(-0.5f, 0.5f)), end.position + (Vector3)(boxSize * new Vector2(-0.5f, 0.5f)) ); Gizmos.DrawLine( start.position + (Vector3)(boxSize * new Vector2(0.5f, 0.5f)), end.position + (Vector3)(boxSize * new Vector2(0.5f, 0.5f)) ); Gizmos.DrawLine( start.position + (Vector3)(boxSize * new Vector2(0.5f, -0.5f)), end.position + (Vector3)(boxSize * new Vector2(0.5f, -0.5f)) ); } } }
private void Awake() { solid = GetComponent <SolidController>(); Transform startTransform = transform.Find("Start"); Transform endTransform = transform.Find("End"); if (startTransform == null || endTransform == null) { Debug.LogWarning( "WARN MovingPlatform.Awake: Can't find start/end point of " + Utils.GetFullName(transform) ); } else { start = startTransform.position; end = endTransform.position; startTransform.gameObject.SetActive(false); endTransform.gameObject.SetActive(false); awake = true; } }