Quantcast
Channel: Questions in topic: "independent"
Viewing all articles
Browse latest Browse all 102

Moving a single instance

$
0
0
I draw a line on which I want to add "handles", these "handles" can be moved and leave a line from their respective anchorpoint, to the new position of their respective "handle". So I made a prefab "handle" which gets instantiated on the line after a certain distance from the last "handle" was drawn. Each handle should be able to move independently, because I want to use the line length for other calculations. But when I have more than 1 instance, all overlap when I try to move a single "handle". Here's some code to elaborate: var rubberBand:GameObject; private var uniqueRubberBand:GameObject; private var rubberBandName:String; uniqueRubberBand = Instantiate(rubberBand, Vector3(linepos.x, linepos.y + 5, linepos.z), transform.rotation); rubberBandName = "RubberBand"; rubberBandName = rubberBandName.Insert(rubberBandName.Length, rubberBandNameArray.length.ToString()); Now for the line drawing, that is happening in a script attached to the prefab: function Start () { anchor = transform.position; drag = false; //Line1 line = new LineRenderer(); line = gameObject.AddComponent(LineRenderer); material = new Material(Shader.Find("Diffuse")); material.color = Color.red; line.material = material; line.SetVertexCount(0); line.SetWidth(startWidth, endWidth); //Line2 lineHelper2 = new GameObject(); lineHelper2.name = this.name + "lineHelper2"; line2 = new LineRenderer(); line2 = lineHelper2.AddComponent(LineRenderer); line2.SetVertexCount(0); line2.SetWidth(startWidth, endWidth); material2 = new Material(Shader.Find("Diffuse")); material2.color = Color.blue; line2.material = material2; //Line3 ... } function Update() {... line.SetVertexCount(2); line.SetPosition(0, anchor); line.SetPosition(1, anchor + unitVector * 25); line2.SetVertexCount(2); line2.SetPosition(0, anchor + unitVector * 25); line2.SetPosition(1, anchor + unitVector * 50); line3.SetVertexCount(2); line3.SetPosition(0, anchor + unitVector * 50); line3.SetPosition(1, transform.position); ...}

Viewing all articles
Browse latest Browse all 102

Trending Articles