@@ -115,7 +115,7 @@ public virtual void InitalizePointer(VRTK_Pointer givenPointer, VRTK_PolicyList
115115 navMeshCheckDistance = givenNavMeshCheckDistance ;
116116 headsetPositionCompensation = givenHeadsetPositionCompensation ;
117117
118- if ( controllingPointer && controllingPointer . interactWithObjects && controllingPointer . controller && ! objectInteractor )
118+ if ( controllingPointer != null && controllingPointer . interactWithObjects && controllingPointer . controller && ! objectInteractor )
119119 {
120120 controllerGrabScript = controllingPointer . controller . GetComponent < VRTK_InteractGrab > ( ) ;
121121 CreateObjectInteractor ( ) ;
@@ -138,11 +138,16 @@ public virtual void ResetPointerObjects()
138138 /// <param name="actualState">The actual state of the activation button press.</param>
139139 public virtual void Toggle ( bool pointerState , bool actualState )
140140 {
141- if ( controllingPointer && ! pointerState )
141+ if ( pointerState )
142+ {
143+ destinationHit = new RaycastHit ( ) ;
144+ }
145+ else if ( controllingPointer != null )
142146 {
143147 controllingPointer . ResetActivationTimer ( ) ;
144148 PointerExit ( destinationHit ) ;
145149 }
150+
146151 ToggleInteraction ( pointerState ) ;
147152 ToggleRenderer ( pointerState , actualState ) ;
148153 }
@@ -161,7 +166,7 @@ public virtual void ToggleInteraction(bool state)
161166 /// </summary>
162167 public virtual void UpdateRenderer ( )
163168 {
164- if ( playareaCursor )
169+ if ( playareaCursor != null )
165170 {
166171 playareaCursor . SetHeadsetPositionCompensation ( headsetPositionCompensation ) ;
167172 playareaCursor . ToggleState ( IsCursorVisible ( ) ) ;
@@ -183,7 +188,7 @@ public virtual RaycastHit GetDestinationHit()
183188 /// <returns>Returns true if there is a valid play area and no collisions. Returns false if there is no valid play area or there is but with a collision detected.</returns>
184189 public virtual bool ValidPlayArea ( )
185190 {
186- return ( ! playareaCursor || ! playareaCursor . IsActive ( ) || ! playareaCursor . HasCollided ( ) ) ;
191+ return ( playareaCursor == null || ! playareaCursor . IsActive ( ) || ! playareaCursor . HasCollided ( ) ) ;
187192 }
188193
189194 /// <summary>
@@ -247,7 +252,7 @@ protected virtual void OnEnable()
247252 protected virtual void OnDisable ( )
248253 {
249254 DestroyPointerObjects ( ) ;
250- if ( objectInteractor )
255+ if ( objectInteractor != null )
251256 {
252257 Destroy ( objectInteractor ) ;
253258 }
@@ -263,7 +268,7 @@ protected virtual void OnValidate()
263268
264269 protected virtual void FixedUpdate ( )
265270 {
266- if ( controllingPointer && controllingPointer . interactWithObjects && objectInteractor && objectInteractor . activeInHierarchy )
271+ if ( controllingPointer != null && controllingPointer . interactWithObjects && objectInteractor != null && objectInteractor . activeInHierarchy )
267272 {
268273 UpdateObjectInteractor ( ) ;
269274 }
@@ -273,16 +278,16 @@ protected virtual void FixedUpdate()
273278
274279 protected virtual void ToggleObjectInteraction ( bool state )
275280 {
276- if ( controllingPointer && controllingPointer . interactWithObjects )
281+ if ( controllingPointer != null && controllingPointer . interactWithObjects )
277282 {
278- if ( state && controllingPointer . grabToPointerTip && controllerGrabScript && objectInteractorAttachPoint )
283+ if ( state && controllingPointer . grabToPointerTip && controllerGrabScript != null && objectInteractorAttachPoint != null )
279284 {
280285 savedAttachPoint = controllerGrabScript . controllerAttachPoint ;
281286 controllerGrabScript . controllerAttachPoint = objectInteractorAttachPoint . GetComponent < Rigidbody > ( ) ;
282287 attachedToInteractorAttachPoint = true ;
283288 }
284289
285- if ( ! state && controllingPointer . grabToPointerTip && controllerGrabScript )
290+ if ( ! state && controllingPointer . grabToPointerTip && controllerGrabScript != null )
286291 {
287292 if ( attachedToInteractorAttachPoint )
288293 {
@@ -294,7 +299,7 @@ protected virtual void ToggleObjectInteraction(bool state)
294299 savedBeamLength = 0f ;
295300 }
296301
297- if ( objectInteractor )
302+ if ( objectInteractor != null )
298303 {
299304 objectInteractor . SetActive ( state ) ;
300305 }
@@ -342,7 +347,7 @@ protected virtual void PointerExit(RaycastHit givenHit)
342347 protected virtual bool ValidDestination ( )
343348 {
344349 bool validNavMeshLocation = false ;
345- if ( destinationHit . transform )
350+ if ( destinationHit . transform != null )
346351 {
347352 NavMeshHit hit ;
348353 validNavMeshLocation = NavMesh . SamplePosition ( destinationHit . point , out hit , navMeshCheckDistance , NavMesh . AllAreas ) ;
@@ -356,7 +361,7 @@ protected virtual bool ValidDestination()
356361
357362 protected virtual void ToggleElement ( GameObject givenObject , bool pointerState , bool actualState , VisibilityStates givenVisibility , ref bool currentVisible )
358363 {
359- if ( givenObject )
364+ if ( givenObject != null )
360365 {
361366 currentVisible = ( givenVisibility == VisibilityStates . AlwaysOn ? true : pointerState ) ;
362367
@@ -401,7 +406,7 @@ protected virtual void MakeRenderersVisible()
401406
402407 protected virtual void ToggleRendererVisibility ( GameObject givenObject , bool state )
403408 {
404- if ( givenObject )
409+ if ( givenObject != null )
405410 {
406411 Renderer [ ] renderers = givenObject . GetComponentsInChildren < Renderer > ( ) ;
407412 for ( int i = 0 ; i < renderers . Length ; i ++ )
@@ -413,7 +418,7 @@ protected virtual void ToggleRendererVisibility(GameObject givenObject, bool sta
413418
414419 protected virtual void SetupMaterialRenderer ( GameObject givenObject )
415420 {
416- if ( givenObject )
421+ if ( givenObject != null )
417422 {
418423 MeshRenderer pointerRenderer = givenObject . GetComponent < MeshRenderer > ( ) ;
419424 pointerRenderer . shadowCastingMode = UnityEngine . Rendering . ShadowCastingMode . Off ;
@@ -424,7 +429,7 @@ protected virtual void SetupMaterialRenderer(GameObject givenObject)
424429
425430 protected virtual void ChangeColor ( Color givenColor )
426431 {
427- if ( ( playareaCursor && playareaCursor . IsActive ( ) && playareaCursor . HasCollided ( ) ) || ! ValidDestination ( ) || ( controllingPointer && ! controllingPointer . CanSelect ( ) ) )
432+ if ( ( playareaCursor != null && playareaCursor . IsActive ( ) && playareaCursor . HasCollided ( ) ) || ! ValidDestination ( ) || ( controllingPointer != null && ! controllingPointer . CanSelect ( ) ) )
428433 {
429434 givenColor = invalidCollisionColor ;
430435 }
@@ -438,21 +443,21 @@ protected virtual void ChangeColor(Color givenColor)
438443
439444 protected virtual void ChangeMaterial ( Color givenColor )
440445 {
441- if ( playareaCursor )
446+ if ( playareaCursor != null )
442447 {
443448 playareaCursor . SetMaterialColor ( givenColor , IsValidCollision ( ) ) ;
444449 }
445450 }
446451
447452 protected virtual void ChangeMaterialColor ( GameObject givenObject , Color givenColor )
448453 {
449- if ( givenObject )
454+ if ( givenObject != null )
450455 {
451456 Renderer [ ] foundRenderers = givenObject . GetComponentsInChildren < Renderer > ( ) ;
452457 for ( int i = 0 ; i < foundRenderers . Length ; i ++ )
453458 {
454459 Renderer foundRenderer = foundRenderers [ i ] ;
455- if ( foundRenderer . material )
460+ if ( foundRenderer . material != null )
456461 {
457462 foundRenderer . material . EnableKeyword ( "_EMISSION" ) ;
458463
@@ -505,7 +510,7 @@ protected virtual void CreateObjectInteractor()
505510
506511 protected virtual void ScaleObjectInteractor ( Vector3 scaleAmount )
507512 {
508- if ( objectInteractor )
513+ if ( objectInteractor != null )
509514 {
510515 objectInteractor . transform . localScale = scaleAmount ;
511516 }
@@ -521,12 +526,12 @@ protected virtual void CreatePointerOriginTransformFollow()
521526
522527 protected virtual float OverrideBeamLength ( float currentLength )
523528 {
524- if ( ! controllerGrabScript || ! controllerGrabScript . GetGrabbedObject ( ) )
529+ if ( controllerGrabScript == null || ! controllerGrabScript . GetGrabbedObject ( ) )
525530 {
526531 savedBeamLength = 0f ;
527532 }
528533
529- if ( controllingPointer && controllingPointer . interactWithObjects && controllingPointer . grabToPointerTip && attachedToInteractorAttachPoint && controllerGrabScript && controllerGrabScript . GetGrabbedObject ( ) )
534+ if ( controllingPointer != null && controllingPointer . interactWithObjects && controllingPointer . grabToPointerTip && attachedToInteractorAttachPoint && controllerGrabScript != null && controllerGrabScript . GetGrabbedObject ( ) )
530535 {
531536 savedBeamLength = ( savedBeamLength == 0f ? currentLength : savedBeamLength ) ;
532537 return savedBeamLength ;
@@ -536,7 +541,7 @@ protected virtual float OverrideBeamLength(float currentLength)
536541
537542 protected virtual void UpdateDependencies ( Vector3 location )
538543 {
539- if ( playareaCursor )
544+ if ( playareaCursor != null )
540545 {
541546 playareaCursor . SetPlayAreaCursorTransform ( location ) ;
542547 }
0 commit comments