Uninomicon

Documenting the dark corners of the Unity Engine.

User Tools

Site Tools


raycasthit2d

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
Last revision Both sides next revision
raycasthit2d [2021/05/05 06:57]
andrew900460 created
raycasthit2d [2021/05/05 16:53]
uninomiconadmin
Line 1: Line 1:
-''RaycastHit2D'' can be used in an if statement to tell if the raycast hit anything, or if it hit nothing.+====== RaycastHit2D ======
  
-Example+==== Casts Implicitly To a Bool ==== 
-<code>+RaycastHit2D implements the C# [[https://forum.unity.com/threads/c-beginner-tips-1-your-friend-the-implicit-bool.185761/|implicit bool]] operator. This allows it to be used in an if statement to check whether a hit is found. 
 +++++ Example | 
 +<code c#>
 RaycastHit2D hit = Physics2D.Raycast(someStartPoint, someDirection); RaycastHit2D hit = Physics2D.Raycast(someStartPoint, someDirection);
  
Line 9: Line 11:
 } }
 </code> </code>
 +
 +This is also valid:
 +<code c#>
 +RaycastHit2D hit = Physics2D.Raycast(someStartPoint, someDirection);
 +
 +bool rayHitSomthing = hit;
 +</code>
 +++++
raycasthit2d.txt · Last modified: 2021/05/05 16:57 by uninomiconadmin