Exemple #1
0
    /// <summary>
    /// Awake is called when the script instance is being loaded.
    /// </summary>
    void Awake()
    {
        //Get the managers requiered to spawn balls.
        levelManager     = GameObject.FindGameObjectWithTag("LevelManager");
        ballManager      = levelManager.GetComponent <BallManager>();
        maxNumberOfBalls = ballManager.maxNumberOfBalls;

        //Get the players health.
        player       = GameObject.FindGameObjectWithTag("Player").transform;
        playerHealth = player.GetComponent <PlayerHealth>();

        //Get the player range detector from the child. It is this big cos is uses the same behavior as EnemyMovement so GetComponentInChildren can't guarantee getting the right instance of the code for
        //the behavior desiered.
        GameObject PlayerFiringRange = transform.Find("PlayerFiringRange").gameObject;

        if (PlayerFiringRange != null)
        {
            Debug.Log("PlayerFiringRange was found");
            PlayerFiringRangeCode = PlayerFiringRange.GetComponent <EnemyPlayerDetector>();
            if (PlayerFiringRangeCode != null)
            {
                Debug.Log("PlayerFiringRangeCode obtained");
            }
        }

        //Set the timer and start invokeing the method to spawn balls.
        spawnTimer = Random.Range(20, 40) / 10;
        InvokeRepeating("CreateBall", spawnTimer, spawnTimer);
    }
Exemple #2
0
    void Start()
    {
        itsef = gameObject.GetComponent <EnemyTest>();

        currentLife = maxLife;

        agent = GetComponent <NavMeshAgent>();

        player = GameObject.FindGameObjectWithTag("Player").GetComponent <PlayerController>();

        gm = GameObject.FindGameObjectWithTag("Managers").GetComponent <GameManager>();

        audPlay = GetComponentInChildren <AudioPlayer>();

        stealth = player.GetComponentInChildren <StealthSystem>();

        playerDetector = GetComponentInChildren <EnemyPlayerDetector>();

        sight = GetComponentInChildren <EnemySight>();

        attack = GetComponentInChildren <EnemyAttackArea>();

        execution = GetComponentInChildren <ExecutionArea>();

        rigid = GetComponent <Rigidbody>();

        anim = GetComponent <EnemyAnimations>();

        anim.Initialize();

        playerDetector.Initialize();

        sight.Initialize();

        execution.Initialize();

        states = State.Stationary;

        StationarySet();

        generalWaitOnPointTime = initGeneralWaitOnPointTime;
        waitOnPointTime        = initWaitOnPointTime;
        waitComeFromSound      = initWaitComeFromSound;
        percentageOfWait       = initPercentageOfWait;
    }
Exemple #3
0
    /// <summary>
    /// Awake is called when the script instance is being loaded.
    /// </summary>
    void Awake()
    {
        //Get the player range detectors from the children. They are this big cos they use the same behavior so GetComponentInChildren can't guarantee getting the right instance of the code for
        //the behavior desiered.
        GameObject playerMovementRange = transform.Find("PlayerMovementRange").gameObject;

        if (playerMovementRange != null)
        {
            //Debug.Log("playerMovementRange was found");
            playerMovementRangeCode = playerMovementRange.GetComponent <EnemyPlayerDetector>();
            if (playerMovementRangeCode != null)
            {
                //Debug.Log("playerMovementRangeCode obtained");
            }
        }
        GameObject playerTooClose = transform.Find("PlayerTooCloseRange").gameObject;

        if (playerTooClose != null)
        {
            //Debug.Log("playerTooClose was found");
            playerTooCloseCode = playerTooClose.GetComponent <EnemyPlayerDetector>();
            if (playerTooCloseCode != null)
            {
                //Debug.Log("playerTooCloseCode obtained");
            }
        }

        //Get key components from the player and enemy.
        player       = GameObject.FindGameObjectWithTag("Player").transform;
        playerHealth = player.GetComponent <PlayerHealth>();
        enemyHealth  = GetComponent <EnemyHealth>();
        nav          = GetComponent <NavMeshAgent>();

        //Setup the timer and direction.
        timeLeft  = timerIntervals;
        direction = randomBoolean();
    }