- Home /
Passing an Array between classes
Sorry in advance if this is a dumb question, but there has to be a better way then what I am currently doing.
I have the following,
public class Button : MonoBehaviour {
public int[] Positions = new int[] {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
public static int[] positionstatic = new int[] {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
void Update ()
{
Positions.CopyTo(positionstatic,0);
... code ...}
...other methods...
}
public class Linerender : MonoBehaviour {
doSomething(Button.positionstatic)
}
Thanks in advance!
public int[] Positions = new int[50];
Should achieves the same result as all those zeros. I didn't actually count the zeros.
You can read the array from anywhere with GetComponent
@Bored$$anonymous$$ormon
Sorry I forgot to mention that Positions values all change during runtime.
Answer by psykojello2 · Jun 23, 2014 at 12:08 AM
I'm not sure what exactly you're trying to do, but I'm assuming you want button's Positions variable information from the Linerenderer class.
You could expose a button property of the line renderer and hook the Button object to the line renderer in the inspector:
public class Linerender : MonoBehaviour
{
public Button button;
...
doSomething(button.Positions);
...
}
Unrelated, but I prefer to use List rather than fixed arrays, but that would totally depend on what your code intends to do.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Filling array with Scribtable Objects automaticly? 1 Answer
Help using LitJson 1 Answer
Index Out of Range Exception - can't figure it out 1 Answer
Distribute terrain in zones 3 Answers