예제 #1
0
        private void TestUse()
        {
            if (!Input.GetMouseButton(0))
            {
                if (used != null)
                {
                    used.UnUse(hand);
                    used = null;
                }
            }

            if (Input.GetMouseButtonDown(0))
            {
                var mainCamera = FindCamera();

                RaycastHit hit = new RaycastHit();
                if (!Physics.Raycast(mainCamera.ScreenPointToRay(Input.mousePosition).origin,
                                     mainCamera.ScreenPointToRay(Input.mousePosition).direction, out hit, 100,
                                     Physics.DefaultRaycastLayers)
                    )
                {
                    return;
                }

                used = hit.collider.gameObject.GetComponentsInParent <MonoBehaviour>().Where(mb => mb is IUseable).FirstOrDefault() as IUseable;

                if (used != null)
                {
                    Debug.Log("Using " + hit.collider.gameObject.name);
                    used.Use(hand);
                }
            }
        }