// 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(); }
void OnTriggerExit(Collider other) { if (ClosestItem != null && ClosestItem.gameObject == other.gameObject) { Debug.Log("No ClosestItem"); ClosestItem = null; } }
void OnTriggerEnter(Collider other) { if (other.GetComponent<InteractibleItem>() != null) { Debug.Log("Set ClosestItem to: " + other.name); ClosestItem = other.GetComponent<InteractibleItem>(); } }
void OnTriggerEnter(Collider other) { if (other.GetComponent <InteractibleItem>() != null) { Debug.Log("Set ClosestItem to: " + other.name); ClosestItem = other.GetComponent <InteractibleItem>(); } }
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(); } } }
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); } }
private void InteractWithItem(InteractibleItem item) { item.InteractWith(this); }