bool BladeExist() { Blade4 blade4Script = FindObjectOfType <Blade4>(); if (blade4Script != null) { Debug.Log("Blade Found"); return(true); } else { Debug.Log("Blade not Found"); return(false); } }
IEnumerator SpawnBlade() { blade = Instantiate(bladePrefab, bladeSpawn.position, bladeSpawn.rotation) as GameObject; Blade4 _bladeScript = blade.GetComponent <Blade4>(); AudioSource bladeMovingAudioSource = _bladeScript.bladeMovingAudioSource; bladeMovingAudioSource.pitch = Random.Range(_bladeScript.defaultIdlingPitch - _bladeScript.pitchRangeOffset, _bladeScript.defaultIdlingPitch + _bladeScript.pitchRangeOffset); dirBenchmarkTime = Random.Range(benchmarkTimeMinMax.x, benchmarkTimeMinMax.y); dirBenchmarkSpeed = Random.Range(benchmarkSpeedMinMax.x, benchmarkSpeedMinMax.y); float dirBenchmarkRotateDir; float randomValue; randomValue = Random.value; if (randomValue > .5f) { dirBenchmarkRotateDir = -1; } else { dirBenchmarkRotateDir = 1; } dirBenchmarkTimer = Mathf.Clamp(dirBenchmarkTimer, 0f, dirBenchmarkTime); dirBenchmarkTimer = 0f; startBenchmarkCounting = true; while (dirBenchmarkTimer < dirBenchmarkTime) { bladeDirBenchmark.Rotate(0f, dirBenchmarkSpeed * dirBenchmarkRotateDir, 0f); yield return(null); } yield return(new WaitForSeconds(benchmarkEndWait)); startBenchmarkCounting = false; bladeMovingAudioSource.pitch = Random.Range(_bladeScript.defaultMovingPitch - _bladeScript.pitchRangeOffset, _bladeScript.defaultMovingPitch + _bladeScript.pitchRangeOffset); blade.GetComponent <Blade4>().movingSpeed = initialBladeSpeed[roundNumber - 1]; }