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.