Maybe this is a dump question, but I just start in Unity, sorry.
I have 2 point on the world, both of them have position ( a vector3).
Between them is a LineRenderer. LineRenderer only need 2 point to be draw on world.
lr.SetPosition(0, vector3_0);
lr.SetPosition(1, vector3_1);
I want to change the LineRender with a cube (or any game object).
My try so far:
//Test SampleCub
sampleCube.transform.position = lr.transform.position;
sampleCube.transform.rotation = Quaternion.LookRotation(vector3_0-vector3_1);
Not working. Please help. Thanks
using UnityEngine;
using System.Collections;
public class LinePoints : MonoBehaviour
{
//set the number of points you your line to have in order
public GameObject[] Points;
private LineRenderer line;
private void Start()
{
//Make sure you have a LineRenderer component attached to an empty gameobject
line = GetComponent<LineRenderer>();
}
private void Update()
{
for (int i = 0; i < Points.Length; i++)
{
//Sets Points
line.SetPosition(i, Points*.transform.position);*
}
}
}
Here is a script I wrote that should work for you.
LineRenderers work by setting their positions in code by accessing their component
You want to aling the position of a point with a position of an object so when you move an object the point will move aswell?
If it is that then this code might help:
In this case we will change second point
public GameObject object;
Vector3 point1;
Vector3 point2;
Vector3 objectPos;
Transform tr = object.GetComponent<Transform>();
void update() {
point2 = tr.position;
lr.SetPosition(0,point1);
lr.SetPosition(1, point2);
}