Esempio n. 1
0
    /*
     * Metode que executa les accions que s'han ordenat al Player, (Agafar, Conversar, etc)
     * que requereixen de varies operacions i/o comprovacions
     */
    private void ExecuteAction()
    {
        switch (_characterAction)
        {
        //Anar fins a l'objecte, i afegirlo al inventari
        case CharacterAction.Take:
            if (Vector3.Distance(navi.transform.position, targetLocation) < 0.5)
            {
                targetLocation = navi.transform.position;
                _inventory.Add2(targetObject);
                targetObject     = null;
                _characterAction = CharacterAction.None;
            }
            break;

        //Anar fins al interlocutor, posarnos davant d'ell cara a cara, fer el transfer a la camara de dialeg
        //i llançar el dialeg
        case CharacterAction.Dialog:
            Vector3 agentPos = new Vector3(navi.transform.position.x, 0, navi.transform.position.z);
            //Si el Player esta 2 unitats davant del seu interlocutor, ha de girar fins estar cara a cara amb ell
            if (Vector3.Distance(agentPos, targetLocation) < 0.1)
            {
                targetLocation = agentPos;
                targetRotation = Quaternion.LookRotation(new Vector3(targetObject.transform.position.x, 0, targetObject.transform.position.z) - targetLocation);
                //Si el Player mira cara a cara el seu interlocutor, es fa el transfer de camera, sino gira fins mirar el seu interlocutor
                if (navi.transform.rotation == targetRotation)
                {
                    CCScript.TransferIn(targetObject.GetComponentInChildren <Camera>());
                    targetObject     = null;
                    _characterAction = CharacterAction.None;
                }
                else
                {
                    navi.transform.rotation = Quaternion.Lerp(navi.transform.rotation, targetRotation, Time.time * 0.002f);
                }
            }
            break;
        }
    }