I'm making an app that changes several Game Objects, the code works fine except that cuadro.transform.GetChild(current).transform.position = new Vector3 (0, 0, 0) moves my object 300 units on the Z axis (the same position of the parent GO)
Why is happening this?
public class ChangePaintScript : MonoBehaviour
{
public GameObject cuadro;
private int total;
private int current = 0;
private bool changing = false;
// Use this for initialization
void Start ( )
{
total = cuadro.transform.childCount;
}
// Update is called once per frame
void Update ( )
{
if ( Input.GetKeyDown(KeyCode.Space) || changing )
{
changing = true;
}
if ( changing )
{
cuadro.transform.GetChild(current).Translate(new Vector3 (-1500, 0, 0) * Time.deltaTime);
if ( Mathf.Abs(cuadro.transform.GetChild(current).transform.position.x) > 400 )
{
changing = false;
cuadro.transform.GetChild(current).gameObject.SetActive(false);
cuadro.transform.GetChild(current).transform.position = new Vector3 (0, 0, 0);
current++;
current %= total;
cuadro.transform.GetChild(current).gameObject.SetActive(true);
}
}
}
}
Thanks for your help!!!