Question by 
               iDG27 · Feb 07, 2021 at 05:08 PM · 
                c#raycast3draycastingraycasthit  
              
 
              Accessing Raycast collider from another script
Hey, I'm getting a strange error that happens whenever the Raycast is not colliding.
 NullReferenceException: Object reference not set to an instance of an object
 OilLamp.Update () (at Assets/Scripts/Pickables/OilLamp.cs:31)
I'm programming a lamp that can be interacted if looking or picked up, where you can turn it on or off, from the player script. The code works fine but I'm having a hard time to make the errors stop.
// Oil Lamp public GameObject _this; private Player player; public bool looking;
 void Start()
     {
         player = GameObject.FindGameObjectWithTag("Player").GetComponent<Player>();
     }
 
 void Update()
     {
         if (player.itemRayHit.collider.gameObject == _this) // error
         {
             looking = true;
         } else
         {
             looking = false;
         }
     }
Thank you!
               Comment
              
 
               
              Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                