Quantcast
Channel: Answers by "ThePersister"
Viewing all articles
Browse latest Browse all 99

Answer by ThePersister

$
0
0
This one should be reasonably easy to answer :) Hitting a certain layer leads to the usage of a LayerMask. Normally, you'll only be hitting that / those layers. To invert a LayerMask, add a cute "~" (squiggly) in front of it. Here's some example code. Nero Fires Everything once you click your left mousebutton and then tells you what he hit: [https://www.youtube.com/watch?v=1Io0OQ2zPS4][1] The code: public LayerMask IgnoreMe; private Ray ray; private RaycastHit hit; void Update() { if (Input.GetMouseButtonDown(0)) NeroFiresEverything(); } public void NeroFiresEverything() { // Basic example ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(ray, out hit, 1000f, ~IgnoreMe)) { Debug.Log("Get Rekt " + hit.collider.name); } } You can define what layer(s) to Ignore in the Inspector in a supercool dropdown box. Hope that helps, if anything was unclear let me know, otherwise, please accept the answer :) [1]: https://www.youtube.com/watch?v=1Io0OQ2zPS4

Viewing all articles
Browse latest Browse all 99

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>