Ejemplo n.º 1
0
    void Start()
    {
        target = this.GetComponent <Transform>();
        stat   = this.gameObject.GetComponent <CharacterStat>();
        enemy  = this.gameObject.GetComponent <EnemyAIScript01>();
        GameObject goPlayer = GameObject.FindGameObjectWithTag("Player");

        if (goPlayer == null)
        {
            Debug.LogError("Cant Find Player...");
            Debug.Break();
        }
        player = goPlayer.transform;


        if (target == null)
        {
            Debug.LogError("Target is null");
        }
        if (player == null)
        {
            Debug.LogError("player is null");
        }

        foreach (Canvas c in FindObjectsOfType <Canvas>())
        {
            if (c.renderMode == RenderMode.ScreenSpaceOverlay)
            {
                target    = Instantiate(textPrefab, c.transform).transform;
                enemyText = target.GetChild(0).GetComponent <Text>();
                break;
            }
        }
    }
Ejemplo n.º 2
0
    IEnumerator CreateEnemy()
    {
        while (!isGameOver)
        {
            yield return(new WaitForSeconds(spawnTime));

            if (isGameOver)
            {
                yield break;
            }

            foreach (GameObject enemy in enemyPool)
            {
                if (!enemy)
                {
                    if (!enemy.activeSelf)
                    {
                        int spawnPointIndex = Random.Range(0, points.Length);
                        enemy.transform.position = points[spawnPointIndex].position;
                        enemy.SetActive(true);

                        EnemyAIScript01 AI = enemy.GetComponent <EnemyAIScript01>();
                        if (target != null)
                        {
                            AI.SetTarget(target);
                        }

                        enemyCount++;
                        //Debug.Log("enemyCount : " + enemyCount);
                        break;
                    }
                }
            }
        }
    }