60 Seconds Tutorial | Grappling hook | Unity 2D

Pubblicato il: 12 giugno 2020
sul canale di: 1 Minute Unity
86,684
1.7k

Link to my game: https://play.google.com/store/apps/de...

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);
}
}


In questa pagina del sito puoi guardare il video online 60 Seconds Tutorial | Grappling hook | Unity 2D della durata di ore minuti seconda in buona qualità , che l'utente ha caricato 1 Minute Unity 12 giugno 2020, condividi il link con amici e conoscenti, su youtube questo video è già stato visto 86,684 volte e gli è piaciuto 1.7 mille spettatori. Buona visione!