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

RaycastError

$
0
0
I am using a raycast script to place a 2d object in 2d space, but it keeps coming up with 'Object reference not set to an instance of an object' When i use the same line of code in a 2d world with only 3d objects, it works fine. void Update () { mousePos = Input.mousePosition; RaycastHit hit; Ray ray = Camera.main.ScreenPointToRay (mousePos); // it selects this line if (Physics.Raycast (ray, out hit, 1000)) { if(hit.transform.tag == "PlaceablePath") { for(int i = 0; i < towers.Count; i ++) { if (towers[i].selected == true && Input.GetButtonDown ("Place")) { towers[i].selected = false; GameObject clone = Instantiate(towers[i].towerObject, hit.transform.position, Quaternion.identity) as GameObject; } } } } }

Viewing all articles
Browse latest Browse all 7934

Trending Articles



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