HDTutorial
EN

Playback starts YouTube’s embedded player (privacy-enhanced mode).

60 Seconds Tutorial | Grappling hook | Unity 2D

88,202 views July 5, 2020 1:38

Watch on YouTube
Channel1 Minute Unity

Description from the creator

Link to my game: play.google.com/store/apps/details?id=com.Hoppo…

In this 1 minute tutorial you will learn how to create a grappling, using c# and unity.

Sub to the channel for more usable content that does not waist your precious time.
The code:
public Camera mainCamera;
public LineRenderer _lineRenderer;
public DistanceJoint2D _distanceJoint;

// Start is called before the first frame update
void Start()
{
_distanceJoint.enabled = false;
}

// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.Mouse0))
{
Vector2 mousePos = (Vector2)mainCamera.ScreenToWorldPoint(Input.mousePosition);
_lineRenderer.SetPosition(0, mousePos);
_lineRenderer.SetPosition(1, transform.position);
_distanceJoint.connectedAnchor = mousePos;
_distanceJoint.enabled = true;
_lineRenderer.enabled = true;
}
else if (Input.GetKeyUp(KeyCode.Mouse0))
{
_distanceJoint.enabled = false;
_lineRenderer.enabled = false;
}
if (_distanceJoint.enabled)
{
_lineRenderer.SetPosition(1, transform.position);
}
}

About this tutorial

1 Minute Unity published this 1:38 video tutorial on July 5, 2020. It has been watched 88,202 times on YouTube.

Category
Gaming
Duration
1:38
Published
July 5, 2020
Views
88,202
Likes
1,717

Tags

Share

This tutorial in other languages