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 createCoins(Transform parentTransform)
{
for (int i = 0; i < parentTransform.childCount; i++)
{
GameObject coinObject = (GameObject)Instantiate(Resources.Load("Coin"));
coinObject.name = MapObjectNames.Coin;
GameObject c = parentTransform.GetChild(i).gameObject;
coinObject.transform.position = c.transform.position;
coinObject.transform.localScale = new Vector3(1, 1, 0);
coinObject.transform.parent = coinLayer.transform;
BoxCollider2D childCollider = coinObject.AddComponent();
childCollider.size = new Vector2(0.3f, 0.3f);
childCollider.isTrigger = true;
Destroy(c);
}
}
{
for (int i = 0; i < parentTransform.childCount; i++)
{
GameObject coinObject = (GameObject)Instantiate(Resources.Load
coinObject.name = MapObjectNames.Coin;
GameObject c = parentTransform.GetChild(i).gameObject;
coinObject.transform.position = c.transform.position;
coinObject.transform.localScale = new Vector3(1, 1, 0);
coinObject.transform.parent = coinLayer.transform;
BoxCollider2D childCollider = coinObject.AddComponent
childCollider.size = new Vector2(0.3f, 0.3f);
childCollider.isTrigger = true;
Destroy(c);
}
}