コード例 #1
0
    // Update is called once per frame
    protected override void Update()
    {
        if (Input.GetButton("Fire1"))
        {
            RaycastHit hit;
            Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            if (Physics.Raycast(ray, out hit, 100))
            {
                PickableItem     pickable     = hit.collider.GetComponent <PickableItem>();
                InteractibleItem interactible = hit.collider.GetComponent <InteractibleItem>();

                if (pickable != null)
                {
                    RotateTo(pickable.transform.position);
                    MoveTo(target: pickable.transform.position, reach: InteractingDistance, andThen: () => {
                        PickItem(pickable);
                    });
                }
                else if (interactible != null)
                {
                    RotateTo(interactible.transform.position);
                    MoveTo(target: interactible.transform.position, reach: InteractingDistance, andThen: () => {
                        InteractWithItem(interactible);
                    });
                }
                else
                {
                    RotateTo(hit.point);
                    MoveTo(target: hit.point);
                }
            }
        }

        base.Update();
    }
コード例 #2
0
 void OnTriggerExit(Collider other)
 {
     if (ClosestItem != null && ClosestItem.gameObject == other.gameObject)
     {
       Debug.Log("No ClosestItem");
       ClosestItem = null;
     }
 }
コード例 #3
0
 void OnTriggerEnter(Collider other)
 {
     if (other.GetComponent<InteractibleItem>() != null)
     {
       Debug.Log("Set ClosestItem to: " + other.name);
       ClosestItem = other.GetComponent<InteractibleItem>();
     }
 }
コード例 #4
0
 void OnTriggerExit(Collider other)
 {
     if (ClosestItem != null && ClosestItem.gameObject == other.gameObject)
     {
         Debug.Log("No ClosestItem");
         ClosestItem = null;
     }
 }
コード例 #5
0
 void OnTriggerEnter(Collider other)
 {
     if (other.GetComponent <InteractibleItem>() != null)
     {
         Debug.Log("Set ClosestItem to: " + other.name);
         ClosestItem = other.GetComponent <InteractibleItem>();
     }
 }
コード例 #6
0
    void Update()
    {
        if (_state.State != StateType.In_Game || isUsing || !Input.GetKeyDown(KeyCode.Mouse0))
        {
            return;
        }

        RaycastHit hit;

        if (Physics.Raycast(Camera.position, Camera.forward, out hit, MaxDistance))
        {
            InteractibleItem item = hit.collider.gameObject.GetComponent <InteractibleItem>();
            if (item != null)
            {
                Debug.Log("Picked up item: " + item.name);
                item.Use();
            }
        }
    }
コード例 #7
0
    private void SetInteractible(bool toggle)
    {
        GameObject item = GetSceneObject();

        if (toggle == true)
        {
            if (item.GetComponent <InteractibleItem>() == null)
            {
                InteractibleItem iItem = item.AddComponent <InteractibleItem>();
                iItem.Persistent   = Persistent;
                iItem.MessageLimit = Uses;
                Debug.Log("Item Given Interaction: " + item.name);
            }
        }
        else
        {
            GameObject.Destroy(item.GetComponent <InteractibleItem>());
            Debug.Log("Item Interaction Removed: " + item.name);
        }
    }
コード例 #8
0
 private void InteractWithItem(InteractibleItem item)
 {
     item.InteractWith(this);
 }