Unity crashes when this code runs:
private IEnumerator beam(int count,GameObject proj,Vector3 location,bool isEnemy, int damage)
{
Debug.Log("beam start");
for(int i=0;i<count;i++)
{
ob=Instantiate(proj,location,Quaternion.identity);
pr=ob.GetComponent<projectile>();
pr.damage=damage;
yield return new WaitForSeconds(0.1f);
}
Debug.Log("beam pause");
yield return new WaitForSeconds(2);
hasThree=false;
if(isEnemy)
{
turn++;
}
Debug.Log("beam end");
}
private IEnumerator approach(int count,GameObject proj,Vector3 location,bool isEnemy, int damage)
{
Debug.Log("approaching");
float currentApproach=0;
while(Input.GetAxis("Fire1")==0){
yield return new WaitForSeconds(0.1f);
Debug.Log("waiting for J");
}
while(Input.GetAxis("Fire1")==1 && currentApproach<maxApproach)
{
battleMax.transform.position+=Vector3.right*0.1f;
currentApproach+=0.1f;
yield return new WaitForSeconds(0.05f);
Debug.Log("Waiting for J (2)");
}
Debug.Log("Creating Beam");
yield return StartCoroutine(beam(count,proj,location,isEnemy,damage));
Debug.Log("Beam Done");
while(battleMax.transform.position!=maxPos)
{
battleMax.transform.position+=(battleMax.transform.position-maxPos)/6;
Debug.Log("Returning");
}
battleMax.transform.position=maxPos;
Debug.Log("Done");
mode=0;
}
I have it call approach, which calls beam, and it crashes when the beam is instantiated.
It could be that I am on a crappy computer, but I just wanted to see if anyone else had/could fix this issue.
I can provide any context if needed.