void Awake()
    {
        Time.timeScale = 1;
        menuCanvas.SetActive(false);
        endGameCanvas.SetActive(false);
        tutorialWelcomeCanvas.SetActive(false);
        tutorialTimeline.SetActive(false);
        attackTimeline.SetActive(false);
        isPaused           = false;
        isFinished         = false;
        Instance           = this;
        gameTimer          = 0;
        pauseScript        = GetComponent <PauseScript>();
        tutorialController = GetComponent <TutorialController>();
        soundController    = GetComponent <GameAmbientSoundController>();
        uiController       = GetComponent <UiController>();
        allySpawner        = GetComponent <AllySpawner>();
        uiController.UpdateCoinNumber(coinsAvailable);
        uiController.UpdateHealthPotionsNumber(healthPotionsAvailable);
        uiController.UpdateAllyNumber();
        tutorialCamera.GetComponent <AudioListener>().enabled = false;

        if (isFirstTimePlaying)
        {
            Time.timeScale     = 0;
            isPaused           = true;
            isFirstTimePlaying = false;
            tutorialWelcomeCanvas.SetActive(true);
            generalUICanvas.SetActive(false);
        }
        else
        {
            Time.timeScale = 1;
            isPaused       = false;
            isInTutorial   = false;
            tutorialWelcomeCanvas.SetActive(false);
            generalUICanvas.SetActive(true);
        }
    }
示例#2
0
    // Update is called once per frame
    public override void Update()
    {
        if (LocalTarget == null)
        {
            LocalTarget = AllySpawner.SeekTarget(goldPile.transform, LocalTargetBreachRadius, LocalTargetSeekRadius, EnemiesLayer);
        }

        //if (LocalTarget == null && GlobalTarget == null)
        //{
        //    if (agent && agent.isOnNavMesh && agent.enabled)
        //    {
        //        //agent.Stop();
        //        //anim.SetBool("IsWalking", false);
        //    }

        //    return;
        //}

        // Give up if the target enemy runs too far out.
        if (LocalTarget != null && Vector3.Distance(LocalTarget.transform.position, goldPile.transform.position) > PatrolLimitRadius)
        {
            LocalTarget = null;
        }

        // Give up if the target enemy runs too far out.
        if (GlobalTarget != null && Vector3.Distance(GlobalTarget.transform.position, goldPile.transform.position) > PatrolLimitRadius)
        {
            GlobalTarget = null;
        }

        if (LocalTarget == null && GlobalTarget == null)
        {
            _activeTarget = null;
        }
        else
        {
            _activeTarget = (LocalTarget ?? GlobalTarget).transform.position;
        }


        // No target so go home
        if (_activeTarget == null)
        {
            _activeTarget = Home.transform.position;
        }

        // Facing the target first
        _activeTarget = (_activeTarget + transform.position) / 2;
        var relativePos = _activeTarget.Value - this.GetComponent <Transform>().position;
        var rotation    = Quaternion.LookRotation(relativePos);
        var current     = this.GetComponent <Transform>().rotation;

        transform.localRotation = Quaternion.Slerp(current, rotation, Time.deltaTime * 2);

        if (agent && agent.isOnNavMesh && agent.enabled)
        {
            _anim.SetBool("IsWalking", true);
            agent.destination = _activeTarget.Value;
            agent.speed       = (float)speed;
            agent.Resume();
        }
    }