/// <summary>
        /// Handle the raycastHits to check if one of them touch something
        /// </summary>
        /// <param name="hits">The list of RaycastHits to check</param>
        /// <param name="isOver">the BoolVariable to set if something got hit</param>
        /// <param name="hitPoint">The Hit Point where the raycast collide</param>
        /// <param name="objectOver">The GameEvent to raise with the transform of the hit</param>
        private void HandleOver(List <RaycastHit> hits, BoolVariable isOver, RaycastHitVariable hitPoint, GameEventTransform objectOver)
        {
            //If nothing is hit, we set the hasHit value to false
            if (hits.Count == 0)
            {
                isOver.SetValue(false);
            }
            else
            {
                foreach (var hit in hits)
                {
                    // If something is hit and is not from the Exclusion layer, we set everything and return
                    if (hit.collider.gameObject.layer != pointerRayCast.ExclusionLayer)
                    {
                        var hitTransform = hit.collider.transform;

                        isOver.SetValue(true);

                        hitPoint.SetValue(hit);
                        objectOver.Raise(hitTransform);
                        return;
                    }
                    //If the only hit was on the exclusion layer, we set the hasHit value to false
                    else
                    {
                        isOver.SetValue(false);
                    }
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Check if the Ray from a controller is hitting something
        /// </summary>
        /// <param name="ray">The ray to check</param>
        /// <param name="distance">The maximum distance to which we raycast</param>
        /// <param name="layerToIgnore">The layer(s) to ignore from raycasting</param>
        /// <param name="hitVariable">The RaycastHitVariable in which we store the hit value</param>
        private void RaycastHandler(Ray ray, float distance, int layerToIgnore, ref RaycastHitVariable hitVariable)
        {
            var hits = Physics.RaycastAll(ray, distance, layerToIgnore);

            if (hits.Length > 0)
            {
                var first3DHit = hits.OrderBy(x => x.distance).First();
                hitVariable.SetValue(first3DHit);
                hitVariable.isNull = false;
            }
            else
            {
                hitVariable.isNull = true;
            }
        }