I'm having trouble passing values that are inside an int function to an onclick delegate.
this script causes the object to move in vector3 (-1 to the left and 1 to the right), these two values are inside the (int value), but I am trying to pass them to a delegate, but when inserting it it is adding different values than being in the script
private int index, index2 = 0;
[SerializeField]
private Vector3[] Myposic1, Myposic2;
[SerializeField]
private Button left, right;//here I change the positions of Myposic1, Myposic2
[SerializeField]
private float time;
public int slide = 0;//index between Myposic1, Myposic2.
void Update() {
call();
}
public void previous()
{
slide--;
call();
}
public void next()
{
slide++;
call();
}
void call()
{
if (slide <= 0)
{
slide = 0;
}
if (slide >= 1)
{
slide = 1;
}
if (slide == 0)
{
left.onClick.AddListener(delegate { player(-1); });
right.onClick.AddListener(delegate { player(1); });
this.transform.position = Vector3.Lerp (this.transform.position, Myposic1[index], Time.deltaTime*time);
if (index == Myposic1.Length - 1)
right.interactable = false;
else
right.interactable = true;
if (index == 0)
left.interactable = false;
else
left.interactable = true;
Debug.Log("1");
}
if (slide == 1)
{
left.onClick.AddListener(delegate { player2(-1); });
right.onClick.AddListener(delegate { player2(1); });
this.transform.position = Vector3.Lerp (this.transform.position, Myposic2 [index2], Time.deltaTime*time);
if (index2 == Myposic2.Length - 1)
right.interactable = false;
else
right.interactable = true;
if (index2 == 0)
left.interactable = false;
else
left.interactable = true;
Debug.Log("2");
}
}
public void player(int valor) {
index = index + valor;
}
public void player2(int valor2) {
index2 = index2 + valor2;
}