Move GameObject with transform.position
Hey, I just ran into a problem I have six prefabs (all are sprites) with the same scripts on them. (They get randomly spawned). I realized that one of the prefabs isn't able to move so I decided to try something:
void Update () {
int i = Random.Range(-10, 10);
transform.position = new Vector3(i, i, i);
}
It works on all prefabs except this one. I get no Errors. It isn't set to static. Similar ways like moving with rigidbodies or other commands don't work too. Where could my problem be?
Can you try to use float ins$$anonymous$$d of int to see if it helps. Also try doing fixed values rather than random ie 3.0f, 2.2f, 1.0f. I do have one question for you, are the prefabs randomly spawned in the beginning of the game or thought the game?
Answer by Zhorky · Nov 24, 2015 at 11:28 AM
They normally do work. If an element accepts integers they cast it by themselves.
Solution: I set one of the Animations to a fixed position. I removed it and everything did work.