コード例 #1
0
    // checks for an interactable object on mouseclick, and interacts with it
    public void Click()
    {
        Ray ray = Cam.ScreenPointToRay(Input.mousePosition);

        RaycastHit hit;

        if (Physics.Raycast(ray, out hit))
        {
            //Debug.DrawRay(ray.origin, ray.direction * 100, Color.yellow, 10);
            Interacter i = hit.collider.GetComponent <Interacter>();
            if (i != null)
            {
                i.Interact(gameObject);
                return;
            }
        }
    }
コード例 #2
0
    //Handles any non physics-related inputs (like menus)
    private void Update()
    {
        //Dialogue controls
        if (ConversationManager.Active)
        {
            //Move the selected index right
            if (Input.GetKeyDown(Prefs.Keys.Right))
            {
                ConversationManager.MoveCursor(1);
            }
            //Move the selected index left
            else if (Input.GetKeyDown(Prefs.Keys.Left))
            {
                ConversationManager.MoveCursor(-1);
            }

            //Advance the dialogue
            if (Input.GetKeyDown(Prefs.Keys.Attack_Interact))
            {
                ConversationManager.FinishTalking();
            }
        }
        else
        {
            //Check if the interact/attack button is held down
            if (!Movement.Immobile && !Attacker.Attacking && Input.GetKeyDown(Prefs.Keys.Attack_Interact))
            {
                //If the player is looking at an interactable object
                if (Interacter.Interactable())
                {
                    Interacter.Interact();
                }
                //If the player has a sword
                else if (Attacker.HasSword)
                {
                    Attacker.Attack();
                }
            }
        }
    }