Copying and Pasting cs Code
In cs, like in almost any computer programming language, reading data from a file can be tricky. You add extra lines of code to tell the computer what to do. Sometimes you can copy and paste these lines from other peoples’ code.
For example, you can follow the pattern in this listing: private void createBoosterObjects(Transform parentTransform)
{
for (int i = 0; i < parentTransform.childCount; i++)
{
GameObject boosterObject = (GameObject)Instantiate(Resources.Load("Booster"));
GameObject c = parentTransform.GetChild(i).gameObject;
boosterObject.transform.position = c.transform.position;
boosterObject.transform.localScale = new Vector3(1, 1, 0);
boosterObject.transform.parent = boosterLayer.transform;
BoxCollider2D childCollider = boosterObject.AddComponent();
childCollider.size = new Vector2(0.9f, 0.2f);
childCollider.isTrigger = true;
boosterObject.transform.position -= new Vector3(-0.45f, 0.1f, 0);
boosterObject.name = MapObjectNames.BoostObject;
Destroy(c);
}
}
{
for (int i = 0; i < parentTransform.childCount; i++)
{
GameObject boosterObject = (GameObject)Instantiate(Resources.Load
GameObject c = parentTransform.GetChild(i).gameObject;
boosterObject.transform.position = c.transform.position;
boosterObject.transform.localScale = new Vector3(1, 1, 0);
boosterObject.transform.parent = boosterLayer.transform;
BoxCollider2D childCollider = boosterObject.AddComponent
childCollider.size = new Vector2(0.9f, 0.2f);
childCollider.isTrigger = true;
boosterObject.transform.position -= new Vector3(-0.45f, 0.1f, 0);
boosterObject.name = MapObjectNames.BoostObject;
Destroy(c);
}
}