void OnTriggerExit2D(Collider2D other) { if (other.GetComponentInChildren <AddToObj>() != null) { addToObjScript = other.GetComponentInChildren <AddToObj>(); addToObjScript.kill = true; Debug.Log("exitedCollider"); } }
IEnumerator SpaceJunkController() { yield return(new WaitForSeconds(startWait)); while (true) { for (int i = 0; i < totalJunkCount; i++) { totalJunkCount--; Debug.Log(totalJunkCount); //Create spawnPosition somewhere on the edge of the circle Vector2 spawnPos = Random.insideUnitCircle.normalized * spawnRadius; //Create instance of spaceJunk junkInstance = Instantiate(GenerateRandomSpaceJunk(), spawnPos, Quaternion.identity) as GameObject; addToObjCopy = Instantiate(addToObj, junkInstance.transform.position, Quaternion.identity) as GameObject; addToObjCopy.transform.SetParent(junkInstance.transform); addToObjScript = addToObjCopy.GetComponent <AddToObj>(); addToObjScript.SetScript(this); addToObjScript.SetObj(); //Get Rigidbody2D junkRB = junkInstance.GetComponent <Rigidbody2D>(); //Create random location to move spacejunk in randomLoc = Random.insideUnitCircle * junkThrowRadius; //Subtract randomLoc from the spawn position to throw junk in that direction. randomDir = randomLoc - spawnPos; //Create a random velocity to throw obj at randomVelocity = Random.Range(lowerRandomVelocity, upperRandomVelocity); //Adjust its rotation rotVector = junkInstance.transform.rotation.eulerAngles; rotVector.z = Random.Range(0, 360); junkInstance.transform.rotation = Quaternion.Euler(rotVector); //Finally add force to the object junkRB.AddForce(randomDir * randomVelocity); yield return(new WaitForSeconds(spawnWait)); } yield return(new WaitForSeconds(waveWait)); Debug.Log("Working"); if (stop && devMode) { Debug.Log("SJS OFF"); yield break; } } }