Quantcast
Channel: Questions in topic: "ios"
Viewing all articles
Browse latest Browse all 4709

Raycast hit Not Set to an instance object

$
0
0
I'm trying to get an enemy to turn around when a wall is in front, for which I set a raycast to detect if the collider name was a wall. When trying to test the code, it shoots the error "Object reference not set to an instance of an object". I don't see the problem. here is the code void WallDetection() { RaycastHit2D wallRay = Physics2D.Raycast(wallDetect.position, Vector2.right, 4f); if (wallRay.collider.name == "Wall Right") { moveRight = false; } else if (wallRay.collider.name == "Wall Left") { moveRight = true; }

Viewing all articles
Browse latest Browse all 4709

Trending Articles



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