Exemplo n.º 1
0
    private void StartAtCheckPoint()
    {
        PlayerMovement player = FindObjectOfType <PlayerMovement>();
        NavMeshAgent   agent  = player.GetComponent <NavMeshAgent>();

        //Move the player
        agent.enabled             = false;
        player.transform.position = transform.position + new Vector3(0, 2, 0.5f);
        agent.enabled             = true;
        FindObjectOfType <PlayerMovement>().GetComponent <Keybearer>().posessedKey = PlayerPrefs.GetInt("PlayerKey");
        //Move Companion
        if (PlayerPrefs.HasKey("CompanionPresent"))
        {
            mCompanion         = GameObject.Find(PlayerPrefs.GetString("CompanionPresent")).GetComponent <CompanionAI>();
            player.myCompanion = mCompanion;
            agent         = mCompanion.GetComponent <NavMeshAgent>();
            agent.enabled = false;
            if (PlayerPrefs.HasKey("DropOffLocation"))
            {
                mCompanion.transform.position = GameObject.Find(PlayerPrefs.GetString("DropOffLocation")).transform.position + new Vector3(0, 2, -0.5f);
            }
            else if (PlayerPrefs.HasKey("CompanionX"))
            {
                mCompanion.transform.position = new Vector3(PlayerPrefs.GetFloat("CompanionX"), PlayerPrefs.GetFloat("CompanionY") + 2, PlayerPrefs.GetFloat("CompanionZ") - 0.5f);
            }
            else
            {
                mCompanion.transform.position = transform.position + new Vector3(0, 2, -0.5f);
            }

            agent.enabled = true;
        }
    }
Exemplo n.º 2
0
    // Update is called once per frame
    void Update()
    {
        if (tellingCompanionWhereToGo)
        {
            if (companionToMove != null)
            {
                companionToMove.GetComponent <NavMeshAgent>().SetDestination(magnetPoint.transform.position);
                if (Vector3.Distance(companionToMove.transform.position, magnetPoint.transform.position) <= 2.0f)
                {
                    companionToMove.GetComponent <Animator>().SetFloat("Speed", 0f);
                }

                if (endOnTimer)
                {
                    if (Time.time > magnetTime + magnetStartTime)
                    {
                        ReturnCompanion();
                    }
                }
            }
        }
    }