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

Raycasthit NullRException

$
0
0
Well, i'm trying to make a simple Collision Side detection with raycast based on [this example][1] [1]: http://www.facebook.com/l.php?u=http%3A%2F%2Fanswers.unity3d.com%2Fquestions%2F339532%2Fhow-can-i-detect-which-side-of-a-box-i-collided-wi.html&h=vAQFewUIW But i'm getting a NullReferenceException at this line: normal = rcashit.transform.TransformDirection(normal); Code: if (col.gameObject.tag == "Player") { Ray obray = new Ray(col.gameObject.transform.position, (col.gameObject.transform.position - transform.position).normalized); RaycastHit rcashit; Physics.Raycast(obray, out rcashit); Vector3 normal = rcashit.normal; normal = rcashit.transform.TransformDirection(normal); if (normal == rcashit.transform.right) { t += 1; if (t >= 30) { PlayerController p = target.GetComponent(); p.health -= 1; t = 0; } } } Can please someone help me? Thanks!

Viewing all articles
Browse latest Browse all 7934

Latest Images

Trending Articles



Latest Images

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