So i have the most recent update of unity and it was running fine. Unity was crashing before for no reason so i deleted it off of my computer. Now its re-installed and actually working, i was able to rebuild my game and re-import my code. When i went to test the simple things it was working but when i started adding the in complex buildings unity just crashes. Its not because the graphical power was to much, its just a few blocks, but the code was a lot more complex. I just found out that it’s the code that crashing the program theres also a stackoverflowexception error with it that i can’t seem to find the root cause of in the program. Can you help me find out why this code is crashing the program.
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class ArcheryTowerScript : MonoBehaviour {
public GameObject Arrow;
public Transform myTransform;
public List<Transform> EnemyArray = new List<Transform>();
public int value = 0;
public int value1 = 0;
public Transform Cube;
ArcheryTowerScript call = new ArcheryTowerScript();
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if(EnemyArray.Count > 0)
{
value = 1;
call.arrowCreation();
}
if(EnemyArray.Count <= 0)
{
value = 0;
}
}
IEnumerator OnTriggerEnter(Collider collision)
{
yield return new WaitForSeconds(0.1f);
if(collision.transform.tag == "Enemy")
{
EnemyArray.Add(Cube);
}
}
void OnTriggerExit(Collider collision)
{
if(collision.transform.tag == "Enemy")
{
EnemyArray.RemoveAt(0);
}
}
public Transform recentEnemy()
{
return EnemyArray[0];
}
public void setCube(Transform myCube)
{
Cube = myCube;
}
public IEnumerator arrowCreation()
{
value1 = 1;
if(value == 1)
{
for(int x = 0; x < 10; x++)
{
Instantiate(Arrow, new Vector3(myTransform.position.x,myTransform.position.y,myTransform.position.z), Quaternion.identity);
yield return new WaitForSeconds(1);
x = 0;
}
}
}
}