How to draw a line and a triangle to build an arrow between two objects

Hi have start to build a new game and i need to buid an arrow were is done by the mouse button down and drag like this example i find on youtube.
Original link
i have try to do it and i all much archive what i need but i set in my example to the input.mousebutton.x ,y, z but i liked to change the coords to my first game object and then finish on the target.
this is what i have get until now
code bellow


This is my code

using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using System.Collections.Generic;
using UnityEngine.EventSystems;

public class Draggable : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDragHandler {

    public Transform parentToReturnTo = null;
    public Transform placeholderParent = null;
    public GameObject cadr1;
    public GameObject cadr2;
    public GameObject cadr3;
    public GameObject cadr4;
    public GameObject enemycard1;
    public GameObject enemycard2;
    public GameObject enemycard3;
    public GameObject enemycard4;
    public Material mater1;
    public float linewith;
    public float depth = 5;
    public GameObject mira;
    public LineRenderer line;

    GameObject placeholder = null;
  
    public void OnBeginDrag(PointerEventData eventData) {
        Debug.Log ("OnBeginDrag");
      
        placeholder = new GameObject();
        placeholder.transform.SetParent( this.transform.parent );
        LayoutElement le = placeholder.AddComponent<LayoutElement>();
        le.preferredWidth = this.GetComponent<LayoutElement>().preferredWidth;
        le.preferredHeight = this.GetComponent<LayoutElement>().preferredHeight;
        le.flexibleWidth = 0;
        le.flexibleHeight = 0;
      
        placeholder.transform.SetSiblingIndex( this.transform.GetSiblingIndex() );
      
        parentToReturnTo = this.transform.parent;
        placeholderParent = parentToReturnTo;
        this.transform.SetParent( this.transform.parent.parent );
      
        GetComponent<CanvasGroup>().blocksRaycasts = false;
    }
  
    public void OnDrag(PointerEventData eventData) {
        //Debug.Log ("OnDrag");
        placeholder.transform.position = Input.mousePosition;
        this.transform.position = Vector3.Lerp(this.transform.position, eventData.position, 0.01f);
        mira.SetActive (true);
        mira.transform.position = Input.mousePosition;
        line = transform.GetComponent<LineRenderer> ();
        line.SetVertexCount (20);
        //line.SetPosition (0, new Vector3 (Input.mousePosition.x, Input.mousePosition.y, Input.mousePosition.z));
        line.SetPosition (0, new Vector3 (Input.mousePosition.x, Input.mousePosition.y, Input.mousePosition.z));
        if(placeholder.transform.parent != placeholderParent)
            placeholder.transform.SetParent(placeholderParent);
      
        int newSiblingIndex = placeholderParent.childCount;
      
        for(int i=0; i < placeholderParent.childCount; i++) {
            if(this.transform.position.x < placeholderParent.GetChild(i).position.x) {
              
                newSiblingIndex = i;
              
                if(placeholder.transform.GetSiblingIndex() < newSiblingIndex)
                    newSiblingIndex--;
              
                break;
            }
        }


        placeholder.transform.SetSiblingIndex(newSiblingIndex);
      
    }
  
    public void OnEndDrag(PointerEventData eventData) {
        Debug.Log ("OnEndDrag");

        this.transform.SetParent( parentToReturnTo );
        this.transform.SetSiblingIndex( placeholder.transform.GetSiblingIndex() );
        GetComponent<CanvasGroup>().blocksRaycasts = true;

        Destroy(placeholder);


    }
    void Start()
    {
        mira.SetActive (false);
    }
    void Update()
    {
      
    }
  
}

Here is the screenshot i have take from it with the example

You should try to attempt this yourself and post your code if you still need help. Plenty of resources out there, you just need to look.

1 Like

Hi hello , tank you for the replay in fact i have try to do like you say and all much archive what i need but i need to ser to start on my gameobject in this case my card and then the line continue follow the traget, can you pls give a litle help . Tank you in advance

That’s better. So with your current code, what is happening or not happening the way you want it to?

1 Like

Hi hello , Tank you for the replay, well in my code wen i start drag the card is start by insert the target in same position of the mouse here the target is not correct place is distante from the mouse position, then the same time is start to draw the line but here i have the problem wen i drag the card to the midle is activate this line and and taget funtion then you drag the target until the enemy card but the line is start in the first position i haved before and not were is the card.
Iliked to drag the card to the midle and then the line start in the new position of the card and not in the first point.
like you can see in screenshoot

Tank you in advance