How to get transform.position of a line renderer

Hello, currently i am creating a game based on, drawing, basicly you draw a object (for example a ball), and it reorganizes the shape, and then it instates a object in it’s place, but i don’t know how to get the transform.position of the line render, so i can instantiate it in its place.
P.S: also it would help if you know how to erase a line renderer points using the mouse.

You want the last point of the line renderer, or you just want its transform’s position?

i want its transform, like this pivot point:

i want that position

What does your current code look like?

First, let’s be clear about terminology: I’m fairly certain you’re looking at the LineRenderer’s bounding box center, NOT transform.position. At the top left in the main Unity window, just after the little tool selector, you have a pair of toggle switches: the first switches between Center/Pivot, the second between Local/Global. Look at the first. If it’s on “Pivot”, that’s transform.position; if it’s on “Center”, that’s the bounding box’s center.

transform.position is obviously easy to get (since that’s literally all of the code), so I assume you need the latter. Bounds is a property of the renderer, so you should be able to use this function to get that:

public Vector3 GetBoundsCenter(Transform t) {
Renderer r = t.GetComponent<Renderer>();
if (r != null) {
return r.bounds.center;
}
else {
return t.position;
}
}
3 Likes

Thank you, this is exactly what i need :slight_smile: