public int AsteroidsspawnOut() { int count = 0; int selector = UnityEngine.Random.Range(0, AsteroidprefabOut.Length); Vector3 pos = transform.localPosition + center + new Vector3(UnityEngine.Random.Range(-sizeOut.x / 2, sizeOut.x / 2), UnityEngine.Random.Range(-sizeOut.y / 2, sizeOut.y / 2), UnityEngine.Random.Range(-sizeOut.z / 2, sizeOut.z / 2)); float avarageScale = (AsteroidprefabOut[selector].transform.localScale.z + AsteroidprefabOut[selector].transform.localScale.y + AsteroidprefabOut[selector].transform.localScale.z) / 4; while (Physics.CheckSphere(pos, spawnRadius * 0.75f * avarageScale, mask)) { pos = transform.localPosition + center + new Vector3(UnityEngine.Random.Range(-sizeOut.x / 2, sizeOut.x / 2), UnityEngine.Random.Range(-sizeOut.y / 2, sizeOut.y / 2), UnityEngine.Random.Range(-sizeOut.z / 2, sizeOut.z / 2)); count++; if (count > 500) { return(0); } } GameObject prefab = AsteroidprefabOut[selector]; GameObject asteroid = Instantiate(prefab, pos, prefab.transform.rotation); asteroid.transform.parent = OutGroup; Obstacle o = asteroid.GetComponent <Obstacle>(); ApplyBehavior bh = asteroid.GetComponent <ApplyBehavior>(); bh.turnLeft = (UnityEngine.Random.Range(0, 2) == 1 ? true : false); bh.player = player.transform; return(1); }
private void OnCollisionEnter(Collision collision) { if (collision.gameObject.CompareTag("AsteroidOut") && collision.gameObject.CompareTag("AsteroidIn") && lastHit != collision.gameObject) { lastHit = collision.gameObject; ApplyBehavior bh = collision.gameObject.GetComponent <ApplyBehavior>(); bh.turnLeft = !bh.turnLeft; } }