- Home /
Question by
lukssoftware · Aug 27, 2015 at 12:33 PM ·
c#raycastprefabspawn
How to spawn prefab only in allowed area?
Hello, I'm using this code to spawn a prefab at mouse position, but I only want it to be allowed to be spawned in the area next to the street object. How can I do this?
if (place_power_plant_coal && Input.GetButtonDown("Fire1")) {
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast(ray, out hit)) {
Instantiate(__power_plant_coal, hit.point, Quaternion.identity);
}
}
Comment