Ejemplo n.º 1
0
    // Update is called once per frame
    void Update()
    {
        if (playerNearby && confirmButton.Pressed() && !DialogueManager.instance.dialogueBox.activeInHierarchy)        //is the player nearby? and the button is pressed and we haven't already turned on the dialogue box
        {
            //send this persons lines to the dialogue manager
            player.GetComponent <PlayerMovement>().DeactivateAllButtons();
            player.GetComponent <PlayerMovement>().SetCanMove(false); //stop the player moving
            DialogueManager.instance.ShowDialogue(lines, isPerson);
            DialogueManager.instance.SetBossWarning(BossWarning);
            DialogueManager.instance.SetTargetNPC(this.gameObject);
        }

        if (playerNearby && BossWarning && !DialogueManager.instance.dialogueBox.activeInHierarchy) //is the player nearby? and this is a boss warning
        {
            player.GetComponent <PlayerMovement>().DeactivateAllButtons();
            player.GetComponent <PlayerMovement>().SetCanMove(false); //stop the player moving

            //send this persons lines to the dialogue manager
            DialogueManager.instance.ShowDialogue(lines, isPerson);
            DialogueManager.instance.SetBossWarning(BossWarning);
            DialogueManager.instance.SetTargetNPC(this.gameObject);
        }
    }
    void FixedUpdate()
    {
#if UNITY_EDITOR || UNITY_STANDALONE || UNITY_WEBPLAYER // the build for PC's control sceheme
        if (canMove)
        {
            Horizontal = Input.GetAxis("Horizontal");
            Vertical   = Input.GetAxis("Vertical");

            Vector3 currentVelocity = gameObject.GetComponent <Rigidbody>().velocity;

            newVelocityX = 0f;
            if (Horizontal < 0 && currentVelocity.x <= 0)
            {
                newVelocityX = -speed;
                animator.SetInteger("DirectionX", -1);
                Up.SetActive(false);
                Down.SetActive(false);
                Right.SetActive(false);
                //TODO play walk sound
            }
            else if (Horizontal > 0 && currentVelocity.x >= 0)
            {
                newVelocityX = speed;
                animator.SetInteger("DirectionX", 1);
                Up.SetActive(false);
                Down.SetActive(false);
                Left.SetActive(false);
                //TODO play walk sound
            }
            else
            {
                animator.SetInteger("DirectionX", 0);
            }

            newVelocityY = 0f;
            if (Vertical < 0 && currentVelocity.y <= 0)
            {
                newVelocityY = -speed;
                animator.SetInteger("DirectionY", -1);
                Up.SetActive(false);
                Left.SetActive(false);
                Right.SetActive(false);
                //TODO play walk sound
            }
            else if (Vertical > 0 && currentVelocity.y >= 0)
            {
                newVelocityY = speed;
                animator.SetInteger("DirectionY", 1);
                Down.SetActive(false);
                Left.SetActive(false);
                Right.SetActive(false);
                //TODO play walk sound
            }
            else
            {
                animator.SetInteger("DirectionY", 0);
            }

            if (newVelocityX == 0 && newVelocityY == 0)
            {
                Up.SetActive(true);
                Down.SetActive(true);
                Left.SetActive(true);
                Right.SetActive(true);

                //TODO stop walk sound
            }

            if (canMove) //if you can move update the player
            {
                gameObject.GetComponent <Rigidbody>().velocity = new Vector3(newVelocityX, 0, newVelocityY);
            }
            else
            {
                gameObject.GetComponent <Rigidbody>().velocity = Vector3.zero;
            }
        }
        else
        {
            Horizontal = 0;
            Vertical   = 0;
            gameObject.GetComponent <Rigidbody>().velocity = Vector3.zero;
            DeactivateAllButtons();
        }
#else //the build for androids controls scheme
        if (canMove)
        {
            Horizontal = 0;
            Vertical   = 0;

            UpButton    = Up.GetComponentInChildren <SimpleTouchArea>();
            DownButton  = Down.GetComponentInChildren <SimpleTouchArea>();
            LeftButton  = Left.GetComponentInChildren <SimpleTouchArea>();
            RightButton = Right.GetComponentInChildren <SimpleTouchArea>();

            Vector3 currentVelocity = gameObject.GetComponent <Rigidbody> ().velocity;

            newVelocityX = 0f;
            if (LeftButton.Pressed() && currentVelocity.x <= 0)
            {
                newVelocityX = -speed;
                animator.SetInteger("DirectionX", -1);
                Up.SetActive(false);
                Down.SetActive(false);
                Right.SetActive(false);
            }
            else if (RightButton.Pressed() && currentVelocity.x >= 0)
            {
                newVelocityX = speed;
                animator.SetInteger("DirectionX", 1);
                Up.SetActive(false);
                Down.SetActive(false);
                Left.SetActive(false);
            }
            else
            {
                animator.SetInteger("DirectionX", 0);
            }

            newVelocityY = 0f;
            if (DownButton.Pressed() && currentVelocity.y <= 0)
            {
                newVelocityY = -speed;
                animator.SetInteger("DirectionY", -1);
                Up.SetActive(false);
                Left.SetActive(false);
                Right.SetActive(false);
            }
            else if (UpButton.Pressed() && currentVelocity.y >= 0)
            {
                newVelocityY = speed;
                animator.SetInteger("DirectionY", 1);
                Down.SetActive(false);
                Left.SetActive(false);
                Right.SetActive(false);
            }
            else
            {
                animator.SetInteger("DirectionY", 0);
            }


            if (newVelocityX == 0 && newVelocityY == 0)
            {
                Up.SetActive(true);
                Down.SetActive(true);
                Left.SetActive(true);
                Right.SetActive(true);
            }

            gameObject.GetComponent <Rigidbody> ().velocity = new Vector3(newVelocityX, 0, newVelocityY);
        }
        else
        {
            Horizontal = 0;
            Vertical   = 0;
            gameObject.GetComponent <Rigidbody>().velocity = Vector3.zero;
            DeactivateAllButtons();
        }
#endif
    }