Hello!!!
So I am new to Unity but I have a script in which I create a new letter every 3 seconds:
IEnumerator createLetters () {
string letters = "abcdefghijklmnopqrstuvwxyz";
while (true) {
GameObject newLetter = new GameObject ();
newLetter.AddComponent<BoxCollider2D> ();
newLetter.tag = "letter";
newLetter.AddComponent<GUIText> ().text = letters [Random.Range (0, letters.Length)].ToString ();
x = Random.Range (0.3f, 0.71f);
y = 1;
pos = new Vector2 (x, y);
newLetter.GetComponent<BoxCollider2D> ().offset = pos;
newLetter.transform.position = pos;
yield return new WaitForSeconds(3);
}
}
As you can see, I add a box collider to it. But this box collider does not appear in the same place as my letter (the GUItext) and I cannot see why not? I know the box collider-offset and the game object’s position is probably not the same thing, but I have tried multiple things and nothing is working the way I want it to.
Can anyone help me?