// Update is called once per frame
    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            ray = mainCamera.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;

            if (Physics.Raycast(ray, out hit, Mathf.Infinity))
            {
                GameObject game = hit.collider.gameObject;

                ItemAcceptor item = game.GetComponent <ItemAcceptor>();
                if (item != null)
                {
                    Visit(item);
                }

                DoorAcceptor door = game.GetComponent <DoorAcceptor>();
                if (door != null)
                {
                    Visit(door);
                }

                ActorAcceptor actor = game.GetComponent <ActorAcceptor>();
                if (actor != null)
                {
                    Visit(actor);
                }
            }
        }
    }
Exemplo n.º 2
0
    // Update is called once per frame
    void Update()
    {
        Ray ray = new Ray(transform.position, transform.forward);

        Debug.DrawRay(ray.origin, ray.direction * InteractDistance, Color.red, 1);
        RaycastHit hit;


        if (Physics.Raycast(ray, out hit, InteractDistance))
        {
            if (hit.collider.CompareTag("KeyItem"))
            {
                if (Input.GetKeyDown(KeyCode.Mouse0))
                {
                    {
                        GameObject game = hit.collider.gameObject;

                        ItemAcceptor item = game.GetComponent <ItemAcceptor>();
                        if (item != null)
                        {
                            Visit(item);              //対象オブジェクトにitemが含まれていればitemにアクセス
                        }
                        DoorAcceptor door = game.GetComponent <DoorAcceptor>();
                        if (door != null)
                        {
                            Visit(door);              //対象オブジェクトにdoorが含まれていればdoorにアクセス
                        }
                        NoteAcceptor note = game.GetComponent <NoteAcceptor>();
                        if (note != null)
                        {
                            Visit(note);              //対象オブジェクトにnoteが含まれていればnoteにアクセス
                        }
                    }
                }
            }
        }
    }
 public override void Visit(DoorAcceptor acceptor)
 {
     acceptor.Accept(this);
     Debug.Log("フィールドを移動する処理");
 }
Exemplo n.º 4
0
 public abstract void Visit(DoorAcceptor acceptor);
Exemplo n.º 5
0
 public override void Visit(DoorAcceptor acceptor)
 {
     acceptor.Accept(this);
     Debug.Log("ドア開閉");
 }