Raycasthit2d



Raycast2d

Frequently in Unity you'll see OnMouseDown used to detect clicks on GameObjects. This works fine but it requires a script on the GameObject itself, and may require synchronization within the game when there are many clickable objects. Grappling gun with raycasthit2D code for Unity. GitHub Gist: instantly share code, notes, and snippets. #JIMMYVEGAS In this Mini Unity Tutorial we show you how to quickly and easily create a RayCast. Subscribe: Patreon: http://patreon.c.

There’s a case when we need to use touch input instead of a mouse button to better handle simultaneous touches and for the multi-touch games. But the cons is you might need to build and run your game every time you want to test it because touch function won’t be executed in Unity Editor. There’s another way to keep the in-editor game functioning well while still keeping touch input for devices by using fake touch function that converts any click into touch phase. This function works well for the non-multi-touch games for the Android platform.

Raycasthit2d

Example of call usage:


Raycasthit2d

Raycasthit2d Array

How is Everhood going

We are doing very good progress on Everhood! Chris is creating more and more in-game content, no one can stop him! From my side (Jordi), I have been working on fixing and creating new in-game logic, don't want to do spoilers but, I bet you will be amazed :D

As I mentioned in Game Localization devlog, trying to not spoil the story and the in-game content is one of our main goals. Here's all we can say for the moment.
To compensate I've made a second mini tutorial/tip for unity c#, you can check the first tutorial/tip here.

Raycasthit2d Example


Lets create a simple 2D laser! - Unity C#

Difficulty: Beginner

Lasers...who doesn't like lasers?

As I love both lasers and each of you, well, let's create the laser logic step by step!

First, let's create a new empty game object and assign a LineRenderer component to it.


Next, make sure to assign the Sprites-default material and set the alignment to 'Transform Z'


Then, create a new script called Laser and open it.

Now let's get the line renderer component at Start().


Raycasthit2d

Next, we need to know when an object collides with the laser, let's use Raycast!


Raycasthit2d

Finally, we need to set line renderer position according to the raycast. Keep in mind that the line renderer have two points 0 and 1, so we need to set both the start point and the end point.

The start point is going to be the main transform position,

2d Raycasting

The end point is going to be the raycast hit point position,

If the raycast don't hit something, just set the end point to an infinite or large value.


Assign Laser script to the empty game object we just created, set editor to play mode et voila!


I hope this mini tutorial was useful!

// Jordi


Wishlist us here so you don't miss any news: