Example #1
0
        // Update is called once per frame
        void Update()
        {
            if (Input.GetMouseButtonDown(0))
            {
                var        cam = Camera.main;
                var        ray = cam.ScreenPointToRay(Input.mousePosition);
                RaycastHit hitInfo;
                var        isHit = Physics.Raycast(ray, out hitInfo, 1 << gameObject.layer);
                if (isHit)
                {
                    var pos      = ray.GetPoint(hitInfo.distance + distanceOffset);
                    var oldValue = terrain.GetCubeAtPos(pos);
                    Debug.Log(oldValue);
                    if (oldValue > 0)
                    {
                        terrain.SetCubeAtPos(pos, 0);
                        terrain.UpdateMesh();
                        return;
                    }
                }

                isHit = Physics.Raycast(ray, out hitInfo, 99f, 1 << trunk.gameObject.layer);
                if (isHit)
                {
                    Debug.Log("ray cast hit");
                    var pos = ray.GetPoint(hitInfo.distance + distanceOffset);
                    trunk.SetCubeAtPos(pos, 0);
                    trunk.UpdateMesh();
                    return;
                }
            }
        }
Example #2
0
 // Update is called once per frame
 void Update()
 {
     if (Input.GetMouseButtonDown(0))
     {
         var        cam = Camera.main;
         var        ray = cam.ScreenPointToRay(Input.mousePosition);
         RaycastHit hitInfo;
         var        isHit = Physics.Raycast(ray, out hitInfo, layer.value);
         if (isHit)
         {
             var pos = ray.GetPoint(hitInfo.distance + distanceOffset);
             trunk.SetCubeAtPos(pos, 0);
             trunk.UpdateMesh();
         }
     }
 }