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

Both sides previous revisionPrevious revision
Next revision
Previous revision
raycasthit2d [2021/05/05 16:53] uninomiconadminraycasthit2d [2025/01/15 04:35] (current) – external edit 127.0.0.1
Line 2: Line 2:
  
 ==== Casts Implicitly To a Bool ==== ==== Casts Implicitly To a Bool ====
- 
 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. 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.
- +<code csharp> 
-++++ Example|+public static implicit operator bool(RaycastHit2D hit) => (Object) hit.collider != (Object) null; 
 +</code> 
 +++++ Example |
 <code c#> <code c#>
 RaycastHit2D hit = Physics2D.Raycast(someStartPoint, someDirection); RaycastHit2D hit = Physics2D.Raycast(someStartPoint, someDirection);
raycasthit2d.1620233608.txt.gz · Last modified: 2025/01/15 04:35 (external edit) · Currently locked by: 217.113.194.140

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki