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*.selected == true && Input.GetButtonDown ("Place"))*
-
{*
_ towers*.selected = false;_
_ GameObject clone = Instantiate(towers.towerObject, hit.transform.position, Quaternion.identity) as GameObject;
}
}
}
}
}*_