Created
April 19, 2015 00:32
-
-
Save nastajus/87cf2ec58c2f0e5ac1f5 to your computer and use it in GitHub Desktop.
nested ifs are the devil. NO! Do flat non-nested ifs instead, by reversing the if-statement negation and exiting instead.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//is called recursively to draw the beam of light | |
public void SetPoint(Vector3 origin, Vector3 direction) | |
{ | |
RaycastHit2D hit = Physics2D.Raycast(origin, direction); | |
//hit something! | |
if (hit.collider != null) | |
{ | |
if (hit.collider.GetComponent<Switch>().passable == true ) | |
{ | |
switch (hit.collider.tag) | |
{ | |
case "Solid": | |
list.Add(hit.point); | |
break; | |
case "Reflect": | |
list.Add(hit.point); | |
Debug.Log("Re flect!!"); | |
break; | |
case "Refract": | |
list.Add(hit.point); | |
Debug.Log("RE FRACT"); | |
break; | |
case "Switch": | |
list.Add(hit.point); | |
Debug.Log(hit.collider.name); | |
break; | |
default: | |
break; | |
} | |
isOutsideScreen = false; | |
} | |
//hit nothing! | |
else | |
{ | |
list.Add(origin + direction * Screen.width); | |
isOutsideScreen = true; | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//is called recursively to draw the beam of light | |
public void SetPoint(Vector3 origin, Vector3 direction) | |
{ | |
RaycastHit2D hit = Physics2D.Raycast(origin, direction); | |
//hit nothing! | |
if (hit.collider == null) | |
{ | |
list.Add(origin + direction * Screen.width); | |
isOutsideScreen = true; | |
return; | |
} | |
//hit somethign | |
else | |
{ | |
switch (hit.collider.tag) | |
{ | |
case "Solid": | |
list.Add(hit.point); | |
break; | |
case "Reflect": | |
list.Add(hit.point); | |
Debug.Log("Re flect!!"); | |
break; | |
case "Refract": | |
list.Add(hit.point); | |
Debug.Log("RE FRACT"); | |
break; | |
case "Switch": | |
list.Add(hit.point); | |
Debug.Log(hit.collider.name); | |
break; | |
default: | |
break; | |
} | |
isOutsideScreen = false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment