Line-Renderer makes Problems

Hey there

I want to make a script, which connects Cubes if there is on char in a string in both cubes the same.

This is my idea:

-Make for each object a line-renderer an give them the position of the other cube, so they connect…

This is my script:

function Verbinden(){  

    for(item25 in SynapsenARR){
		var script11 = item25.GetComponent(LineRenderer);
		Destroy (script11);
		script11 = item25.gameObject.AddComponent(LineRenderer);
	}
    
        
	for(item1 in SynapsenARR){	
		var zahl1 : Synapse = item1.GetComponent("Synapse");
		var counter : int = 0;	
		for(item2 in SynapsenARR){			
			var script1 : Synapse = item1.GetComponent("Synapse");
			var vergleich1 : String = script1.Zahl;
			var script2 : Synapse = item2.GetComponent("Synapse");
			var vergleich2 : String = script2.Zahl;
			if(vergleich1.Length == vergleich2.Length){
				if(item1 != item2){	
					for (var k = 0; k<=(AnzahlDerStellen-1);k++) {
					Debug.Log(k.ToString());				
						if(vergleich1[k] == vergleich2[k]){						
							var script10 = item1.GetComponent(LineRenderer);						
							if (script10 == null)
							{
									script10 = item1.gameObject.AddComponent(LineRenderer);
									script10.material = new Material (Shader.Find("Particles/Additive"));
									script10.SetColors( Color.red,  Color.red);
							}
							
							
							counter += 2;
							script10.SetWidth(0.05, 0.05);
		  					script10.SetVertexCount(counter+1);
							script10.SetPosition(counter-2, item1.transform.position);
							script10.SetPosition(counter-1, item2.transform.position);
						}
					} 
				}
			}
		}
	}
}

SynapsenARR is a List
in Synapse is the string Zahl which should compare.

The Problem is, that when there coming more than 4 Cubes, this script doesn´t works anymore.

The lines jumping around, though their have to be the same.

Where is my mistake?

Thank you for helping me.

Not sure about your problem, but numbers in variables can be a good thing and could lead to errors in the future.

If your destroying the instance at line 5 then your prob not assigning it at line 6.

thanks for your help :slight_smile:

the problem was the VertexCount wasn´t high enough

i solve the script so:

function Verbinden(){  

    for(item25 in SynapsenARR){
		var script11 = item25.GetComponent(LineRenderer);
		if (script11 == null)
		{
				script11 = item25.gameObject.AddComponent(LineRenderer);
				script11.material = new Material (Shader.Find("Particles/Additive"));
				script11.SetColors( Color.red,  Color.red);
		}
		script11.SetVertexCount(AnzahlDerStellen*SynapsenARR.Count*10);
		for (var l = 0; l<=(AnzahlDerStellen*SynapsenARR.Count*10-1);l++) {	
			script11.SetPosition(l, transform.position);
			Debug.Log(l.ToString());
		}
	}
    
        
	for(item1 in SynapsenARR){	
		var zahl1 : Synapse = item1.GetComponent("Synapse");
		var counter : int = 0;	
		for(item2 in SynapsenARR){			
			var script1 : Synapse = item1.GetComponent("Synapse");
			var vergleich1 : String = script1.Zahl;
			var script2 : Synapse = item2.GetComponent("Synapse");
			var vergleich2 : String = script2.Zahl;
			if(vergleich1.Length == vergleich2.Length){
				if(item1 != item2){	
					for (var k = 0; k<=(AnzahlDerStellen-1);k++) {				
						if(vergleich1[k] == vergleich2[k]){						
							var script10 = item1.GetComponent(LineRenderer);						
							if (script10 == null)
							{
									script10 = item1.gameObject.AddComponent(LineRenderer);
									script10.material = new Material (Shader.Find("Particles/Additive"));
									script10.SetColors( Color.red,  Color.red);
							}
							
							
							counter += 2;
							script10.SetWidth(0.05, 0.05);
		  					script10.SetVertexCount(counter+1);
							script10.SetPosition(counter-2, item1.transform.position);
							script10.SetPosition(counter-1, item2.transform.position);
						}
					} 
				}
			}
		}
	}
}

the problem is now, it doesn´t works right:

here are two pictures that shows the renderresult with a box in front with the string Zahl as name.

my question is now:

Why did the script connects them?

please help me…