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: public void addSkill(SkillType type, int animalIndex)
{
switch (type)
{
case SkillType.LUA:
{
GameObject bulletObject = (GameObject)Instantiate(Resources.Load("Bullets/LUA"));
bulletObject.name = "Bullet";
bulletObject.layer = LayerMask.NameToLayer("Animal" + (animalIndex + 1));
bulletObject.transform.parent = bulletLayer.transform;
GameObject animal = animals.getAnimal(animalIndex);
bulletObject.transform.localPosition = new Vector3(animal.transform.localPosition.x, animal.transform.localPosition.y + 0.2f, bulletObject.transform.localPosition.z);
Bullet bullet = bulletObject.GetComponent();
bullet.animalIndex = animalIndex;
}
break;
case SkillType.DONGBANG:
{
GameObject bulletObject = (GameObject)Instantiate(Resources.Load("Bullets/DONGBANG"));
bulletObject.name = "Bullet";
bulletObject.layer = LayerMask.NameToLayer("Animal" + (animalIndex + 1));
bulletObject.transform.parent = bulletLayer.transform;
GameObject animal = animals.getAnimal(animalIndex);
bulletObject.transform.localPosition = new Vector3(animal.transform.localPosition.x, animal.transform.localPosition.y + 0.2f, bulletObject.transform.localPosition.z);
Bullet bullet = bulletObject.GetComponent();
bullet.animalIndex = animalIndex;
}
break;
case SkillType.THIENTHACH:
{
for (int i = 0; i < 3; i++)
{
GameObject bulletObject = (GameObject)Instantiate(Resources.Load("Bullets/THIENTHACH"));
bulletObject.name = "Bullet";
bulletObject.layer = LayerMask.NameToLayer("Animal" + (animalIndex + 1));
bulletObject.transform.parent = bulletLayer.transform;
GameObject animal = animals.getAnimal(animalIndex);
bulletObject.transform.localPosition = new Vector3(animal.transform.localPosition.x + 0.2f, animal.transform.localPosition.y + 0.4f, bulletObject.transform.localPosition.z);
Bullet bullet = bulletObject.GetComponent();
bullet.animalIndex = animalIndex;
}
}
break;
case SkillType.SET:
{
GameObject bulletObject = (GameObject)Instantiate(Resources.Load("Bullets/SET"));
bulletObject.name = "Bullet";
bulletObject.layer = LayerMask.NameToLayer("Animal" + (animalIndex + 1));
bulletObject.transform.parent = bulletLayer.transform;
GameObject animal = animals.getAnimal(animalIndex);
bulletObject.transform.localPosition = new Vector3(animal.transform.localPosition.x + 0.2f, animal.transform.localPosition.y + 0.2f, bulletObject.transform.localPosition.z);
Bullet bullet = bulletObject.GetComponent();
bullet.animalIndex = animalIndex;
}
break;
case SkillType.BOM:
{
GameObject bulletObject = (GameObject)Instantiate(Resources.Load("Bullets/BOM"));
bulletObject.name = "Bullet";
bulletObject.layer = LayerMask.NameToLayer("Animal" + (animalIndex + 1));
bulletObject.transform.parent = bulletLayer.transform;
GameObject animal = animals.getAnimal(animalIndex);
bulletObject.transform.localPosition = new Vector3(animal.transform.localPosition.x , animal.transform.localPosition.y + 0.5f , bulletObject.transform.localPosition.z);
Bullet bullet = bulletObject.GetComponent();
bullet.animalIndex = animalIndex;
}
break;
case SkillType.DOICHO:
{
GameObject bulletObject = (GameObject)Instantiate(Resources.Load("Bullets/DOICHO"));
bulletObject.name = "Bullet";
bulletObject.layer = LayerMask.NameToLayer("Animal" + (animalIndex + 1));
bulletObject.transform.parent = bulletLayer.transform;
GameObject animal = animals.getAnimal(animalIndex);
bulletObject.transform.localPosition = new Vector3(animal.transform.localPosition.x + 0.3f, animal.transform.localPosition.y + 0.2f, bulletObject.transform.localPosition.z);
Bullet bullet = bulletObject.GetComponent();
bullet.animalIndex = animalIndex;
}
break;
case SkillType.BAOVE:
{
Animal animal = animals.getAnimal(animalIndex).GetComponent();
if (!animal.IsProtected)
{
GameObject effectObject = (GameObject)Instantiate(Resources.Load("Effects/BAOVE"));
effectObject.name = "Effect";
effectObject.transform.parent = effectLayer.transform;
effectObject.GetComponent().mapObjectTransform = animal.gameObject.transform;
animal.protectedEffect = effectObject.GetComponent();
}
else
{
animal.protectedEffect.stateTime = 5;
}
animals.getAnimal(animalIndex).GetComponent().setProtected();
}
break;
case SkillType.TANGTOC:
{
GameObject effectObject = (GameObject)Instantiate(Resources.Load("Effects/TANGTOC"));
effectObject.name = "Effect";
effectObject.transform.parent = effectLayer.transform;
effectObject.GetComponent().mapObjectTransform = animals.getAnimal(animalIndex).transform;
animals.getAnimal(animalIndex).GetComponent().setSpeedUp();
}
break;
}
}
{
switch (type)
{
case SkillType.LUA:
{
GameObject bulletObject = (GameObject)Instantiate(Resources.Load
bulletObject.name = "Bullet";
bulletObject.layer = LayerMask.NameToLayer("Animal" + (animalIndex + 1));
bulletObject.transform.parent = bulletLayer.transform;
GameObject animal = animals.getAnimal(animalIndex);
bulletObject.transform.localPosition = new Vector3(animal.transform.localPosition.x, animal.transform.localPosition.y + 0.2f, bulletObject.transform.localPosition.z);
Bullet bullet = bulletObject.GetComponent
bullet.animalIndex = animalIndex;
}
break;
case SkillType.DONGBANG:
{
GameObject bulletObject = (GameObject)Instantiate(Resources.Load
bulletObject.name = "Bullet";
bulletObject.layer = LayerMask.NameToLayer("Animal" + (animalIndex + 1));
bulletObject.transform.parent = bulletLayer.transform;
GameObject animal = animals.getAnimal(animalIndex);
bulletObject.transform.localPosition = new Vector3(animal.transform.localPosition.x, animal.transform.localPosition.y + 0.2f, bulletObject.transform.localPosition.z);
Bullet bullet = bulletObject.GetComponent
bullet.animalIndex = animalIndex;
}
break;
case SkillType.THIENTHACH:
{
for (int i = 0; i < 3; i++)
{
GameObject bulletObject = (GameObject)Instantiate(Resources.Load
bulletObject.name = "Bullet";
bulletObject.layer = LayerMask.NameToLayer("Animal" + (animalIndex + 1));
bulletObject.transform.parent = bulletLayer.transform;
GameObject animal = animals.getAnimal(animalIndex);
bulletObject.transform.localPosition = new Vector3(animal.transform.localPosition.x + 0.2f, animal.transform.localPosition.y + 0.4f, bulletObject.transform.localPosition.z);
Bullet bullet = bulletObject.GetComponent
bullet.animalIndex = animalIndex;
}
}
break;
case SkillType.SET:
{
GameObject bulletObject = (GameObject)Instantiate(Resources.Load
bulletObject.name = "Bullet";
bulletObject.layer = LayerMask.NameToLayer("Animal" + (animalIndex + 1));
bulletObject.transform.parent = bulletLayer.transform;
GameObject animal = animals.getAnimal(animalIndex);
bulletObject.transform.localPosition = new Vector3(animal.transform.localPosition.x + 0.2f, animal.transform.localPosition.y + 0.2f, bulletObject.transform.localPosition.z);
Bullet bullet = bulletObject.GetComponent
bullet.animalIndex = animalIndex;
}
break;
case SkillType.BOM:
{
GameObject bulletObject = (GameObject)Instantiate(Resources.Load
bulletObject.name = "Bullet";
bulletObject.layer = LayerMask.NameToLayer("Animal" + (animalIndex + 1));
bulletObject.transform.parent = bulletLayer.transform;
GameObject animal = animals.getAnimal(animalIndex);
bulletObject.transform.localPosition = new Vector3(animal.transform.localPosition.x , animal.transform.localPosition.y + 0.5f , bulletObject.transform.localPosition.z);
Bullet bullet = bulletObject.GetComponent
bullet.animalIndex = animalIndex;
}
break;
case SkillType.DOICHO:
{
GameObject bulletObject = (GameObject)Instantiate(Resources.Load
bulletObject.name = "Bullet";
bulletObject.layer = LayerMask.NameToLayer("Animal" + (animalIndex + 1));
bulletObject.transform.parent = bulletLayer.transform;
GameObject animal = animals.getAnimal(animalIndex);
bulletObject.transform.localPosition = new Vector3(animal.transform.localPosition.x + 0.3f, animal.transform.localPosition.y + 0.2f, bulletObject.transform.localPosition.z);
Bullet bullet = bulletObject.GetComponent
bullet.animalIndex = animalIndex;
}
break;
case SkillType.BAOVE:
{
Animal animal = animals.getAnimal(animalIndex).GetComponent
if (!animal.IsProtected)
{
GameObject effectObject = (GameObject)Instantiate(Resources.Load
effectObject.name = "Effect";
effectObject.transform.parent = effectLayer.transform;
effectObject.GetComponent
animal.protectedEffect = effectObject.GetComponent
}
else
{
animal.protectedEffect.stateTime = 5;
}
animals.getAnimal(animalIndex).GetComponent
}
break;
case SkillType.TANGTOC:
{
GameObject effectObject = (GameObject)Instantiate(Resources.Load
effectObject.name = "Effect";
effectObject.transform.parent = effectLayer.transform;
effectObject.GetComponent
animals.getAnimal(animalIndex).GetComponent
}
break;
}
}