- Home /
How to target an specific line renderer to a sprite?
How can i basically? edit the position of a line rendereR? i used linerenderer.position but i cant put it, instead it targets the center of the gameobject? how can i cast my linerenderer from the position in my image below? Thanks in advance!
using UnityEngine; using System.Collections;
public class DrawLine : MonoBehaviour { public LineRenderer lineRenderer; private GameObject origin; private GameObject destination;
void Start()
{
origin = GameObject.Find("Player");
destination = GameObject.Find("Destination");
lineRenderer = GetComponent<LineRenderer>();
lineRenderer.SetWidth(.1f, .1f);
}
void Update()
{
lineRenderer.SetPosition(0, origin.transform.position);
lineRenderer.SetPosition(1, destination.transform.position);
}
}
Answer by karljj1 · Feb 24, 2015 at 07:57 PM
transform.position will give you the pivot point of the object. By default this tends to be in the center. You can either adjust the pivot point to be at the end of the rod, if its a unity sprite then this is quite simple using the sprite editor. You can also add an empty gameobject and position it in the correct place and use its position instead.