Quantcast
Channel: Questions in topic: "error message"
Viewing all articles
Browse latest Browse all 2891

Getting rid of error message Raycast?

$
0
0
I'm using Raycast2D to detect ground and project a shadow (see code below). My problem is the error message that seems to appear when the ray doesn't hit anything *"NullReferenceException: Object reference not set to an instance of an object PlayerController.Update () (at Assets/Scripts/PlayerController.cs:175)"*. It messes with the rest of code so that the player sometimes don't die. If I could I would just get rid of the float distance "10f" but without it the shadow seems to disappear when the player moves towards the ground in high speed. RaycastHit2D hit = Physics2D.Raycast(transform.position, Vector2.down, 10f); if (hit.transform.gameObject.layer == LayerMask.NameToLayer("Ground") && dead == false) { shadow.SetActive(true); shadow.transform.position = hit.point; } else { shadow.SetActive(false); }

Viewing all articles
Browse latest Browse all 2891

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>