UnityEngine.Physics.Raycast(UnityEngine.Vector3, UnityEngine.Vector3, out UnityEngine.RaycastHit)

Here are the examples of the csharp api UnityEngine.Physics.Raycast(UnityEngine.Vector3, UnityEngine.Vector3, out UnityEngine.RaycastHit) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

3 Examples 7

19 View Source File : TemporaryManager.cs
License : MIT License
Project Creator : pampas93

private void Update()
    {

        GameObject oldFocusObject = FocusedObject;

        var headPosition = Camera.main.transform.position;
        var gazeDirection = Camera.main.transform.forward;

        RaycastHit hitInfo;
        if (Physics.Raycast(headPosition, gazeDirection, out hitInfo))
        {
            FocusedObject = hitInfo.collider.gameObject;
        }
        else
        {
            FocusedObject = null;
        }

        // If the focused object changed this frame, start detecting fresh gestures again.
        if (FocusedObject != oldFocusObject)
        {
            tapRecognizer.CancelGestures();
            tapRecognizer.StartCapturingGestures();
        }

        if (selectedGameObject != null)
        {
            SelectedObjectDebug.text = "Currently selected: " + selectedGameObject.name;

            //When SelectedGameObject is not null; we know it has a parent; So, we get the parent, getComponents of MSR and enable or disable

            GameObject parent = selectedGameObject.transform.parent.gameObject;

            var moveComponent = parent.GetComponent<MoveScript>();
            var rotateComponent = parent.GetComponent<RotateScript>();
            var scaleComponent = parent.GetComponent<ScaleScript>();

            JustToDebug.text = TransformMenu.instance.currentMode.ToString();

            switch (TransformMenu.instance.currentMode)
            {
                case TransformMenu.Mode.Move:
                    moveComponent.SetDragging(true);
                    rotateComponent.SetRotating(false);
                    scaleComponent.SetResizing(false);
                    break;
                case TransformMenu.Mode.Rotate:
                    rotateComponent.SetRotating(true);
                    moveComponent.SetDragging(false);
                    scaleComponent.SetResizing(false);
                    break;
                case TransformMenu.Mode.Scale:
                    scaleComponent.SetResizing(true);
                    moveComponent.SetDragging(false);
                    rotateComponent.SetRotating(false);
                    break;
                case TransformMenu.Mode.Reset:
                    Debug.Log("**************************Reset is enabled");
                    //TransformMenu.instance.currentMode = TransformMenu.Mode.None;
                    //Call the reset function

                    Debug.Log("Reset is Off~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
                    break;
                default:
                    scaleComponent.SetResizing(false);
                    moveComponent.SetDragging(false);
                    rotateComponent.SetRotating(false);
                    //Debug.Log("Nothing is enabled");
                    break;
            }
        }
        else
            SelectedObjectDebug.text = "Currently selected: None";
    }

19 View Source File : ObjectManager.cs
License : MIT License
Project Creator : pampas93

private void Update()
    {
        
        GameObject oldFocusObject = FocusedObject;

        var headPosition = Camera.main.transform.position;
        var gazeDirection = Camera.main.transform.forward;

        RaycastHit hitInfo;
        if (Physics.Raycast(headPosition, gazeDirection, out hitInfo))
        {
            FocusedObject = hitInfo.collider.gameObject;
        }
        else
        {
            FocusedObject = null;
        }

        // If the focused object changed this frame, start detecting fresh gestures again.
        if (FocusedObject != oldFocusObject)
        {
            tapRecognizer.CancelGestures();
            tapRecognizer.StartCapturingGestures();
        }

        if (selectedGameObject != null)
        {

            //When SelectedGameObject is not null; we know it has a parent; So, we get the parent, getComponents of MSR and enable or disable

            GameObject parent = selectedGameObject.transform.parent.gameObject;

            var moveComponent = parent.GetComponent<MoveScript>();
            var rotateComponent = parent.GetComponent<RotateScript>();
            var scaleComponent = parent.GetComponent<ScaleScript>();

            switch (TransformMenu.instance.currentMode)
            {
                case TransformMenu.Mode.Move:
                    moveComponent.SetDragging(true);
                    rotateComponent.SetRotating(false);
                    scaleComponent.SetResizing(false);
                    break;
                case TransformMenu.Mode.Rotate:
                    rotateComponent.SetRotating(true);
                    moveComponent.SetDragging(false);
                    scaleComponent.SetResizing(false);
                    break;
                case TransformMenu.Mode.Scale:
                    scaleComponent.SetResizing(true);
                    moveComponent.SetDragging(false);
                    rotateComponent.SetRotating(false);
                    break;
                case TransformMenu.Mode.Reset:
                    Debug.Log("**************************Reset is enabled");
                    TransformMenu.instance.currentMode = TransformMenu.Mode.None;
                    //Call the reset function

                    Debug.Log("Reset is Off~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
                    break;
                default:
                    scaleComponent.SetResizing(false);
                    moveComponent.SetDragging(false);
                    rotateComponent.SetRotating(false);
                    //Debug.Log("Nothing is enabled");
                    break;
            }
        }
        else
        {
            //Currently, no object is selected.
        }
    }

19 View Source File : ExtendedTransformEditor.cs
License : MIT License
Project Creator : XINCGer

[MenuItem ("CONTEXT/Transform/Snap to Ground")]
		private static void SnapToGround (MenuCommand command)
		{
			var transform = command.context as Transform;

			RaycastHit hit;
			if (Physics.Raycast (transform.position, Vector3.down, out hit))
			{
				Undo.RecordObject (transform, "Snapped To Ground");
				transform.position = hit.point;
			}
		}