Search Unity

Error in Documentation code

Discussion in 'Documentation' started by schadmigo, Mar 24, 2017.

  1. schadmigo

    schadmigo

    Joined:
    Mar 24, 2017
    Posts:
    1
    https://docs.unity3d.com/560/Documentation/ScriptReference/Plane.Raycast.html

    In my tests the script did nothing, because groundPlane has not been assigned.
    fixed code:

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class ExampleClass : MonoBehaviour {
    5.     public Plane groundPlane;
    6.     public Transform markerObject;
    7.     void Update() {
    8.         if (Input.GetMouseButtonDown(0)) {
    9.             groundPlane = new Plane(new Vector3(0f, 1f, 0f), 0f);
    10.             Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
    11.             float rayDistance;
    12.             if (groundPlane.Raycast(ray, out rayDistance))
    13.                 markerObject.position = ray.GetPoint(rayDistance);
    14.            
    15.         }
    16.     }
    17. }
    works as expected.

    Regards