void Update() { if (m_Delay < m_EnemySpawningDelay) { m_Delay += Time.deltaTime; } else if (m_CurrentIndex < m_EnemyPrefabs.Count) { m_Delay = 0; GameObject enemy = Instantiate(m_EnemyPrefabs[m_CurrentIndex]); if (m_ShootDirection) { EnemyAI ai = enemy.GetComponent <EnemyAI> (); ai.SetShootDirection(m_ShootDirection); } if (m_Curve) { EnemyPath path = enemy.GetComponent <EnemyPath> (); path.SetPath(m_Curve); } enemy.transform.position = m_SpawningLocation.position; m_CurrentIndex++; } else { Destroy(this); } }
protected void SetupGeneral() { Health healthScript = GetComponent <Health> (); if (!healthScript) { healthScript = gameObject.AddComponent <Health> (); } healthScript.SetHealth(health); EnemyPath pathScript = GetComponent <EnemyPath> (); if (!pathScript) { pathScript = gameObject.AddComponent <EnemyPath> (); } pathScript.SetDamageOnCollision(dommageOnCollision); if (!path) { GameObject temp = Instantiate(pathPrefab); StartCoroutine(DestroyFirstWhenSecondDestroyed(temp, gameObject)); path = temp.GetComponent <BezierCurve> (); } pathScript.SetPath(path); if (duration <= 0) { Debug.LogWarning("The duration given wasn't stricly positive, a default duration of 15 secondes will be given instead"); duration = 15; } pathScript.SetDuration(duration); if (onHitSound) { pathScript.SetHitSound(onHitSound); } pathScript.SetLoop(loop); pathScript.SetHitColorTime(onHitColorTime > 0 ? onHitColorTime : 1); }