Why the line appears in the incorrect place ?
Hello everyone, I'm trying to draw a line between 2 objects, and I use a "Line renderer" to make te line ... and the "transform.position" of the objects to make it but I don't understand why the line gets wrong ? Look this Image of the result and my Script... Thanks a lot :)
.- Dave
This is the Script :
using System.Collections;
using System.Collections.Generic;
using UnityEngine.UI;
using UnityEngine;
public class Line : MonoBehaviour {
private LineRenderer lineRenderer;
private float counter;
private float dist;
//Inicio y fin
public Image origin;
public Image destination;
//Velocidad con la que se va a dibujar
public float lineDrawSpeed = 6f;
// Use this for initialization
void Start () {
lineRenderer = GetComponent<LineRenderer>();
lineRenderer.SetPosition(0, origin.transform.position);
lineRenderer.SetPosition(1, destination.transform.position);
Debug.Log(origin.transform.position);
Debug.Log(destination.transform.position);
lineRenderer.SetWidth(.20f, .20f);
dist = Vector3.Distance(origin.transform.position, destination.transform.position);
}
// Update is called once per frame
void Update () {
/*if(counter < dist)
{
counter = (.1f / lineDrawSpeed) + counter;
float x = Mathf.Lerp(0, dist, counter);
Vector3 pointA = origin.transform.position;
Vector3 pointB = destination.transform.position;
Vector3 faithPoint = x * Vector3.Normalize(pointB - pointA) + pointA;
lineRenderer.SetPosition(1, faithPoint);
}*/
}
}
captura-de-pantalla-3.png
(131.8 kB)
Comment