I have a raycast that works in the unity editor but not when I build it for Android( tablet or phone, neither work). The code I'm using is as follows:
public class DirectionalTilePlacing : MonoBehaviour {
public LayerMask levelLayer;
private int tileType;
public int Tiletype
{
get { return tileType; }
set
{
tileType = value;
}
}
RaycastHit hit;
Vector2I placePosition;
// Update is called once per frame
void Update()
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, out hit, Mathf.Infinity, levelLayer))
{
if (hit.collider.tag == "Replaceable")
{
transform.position = new Vector3(Mathf.Floor(hit.point.x) + 0.5f, Mathf.Floor(hit.point.y), Mathf.Floor(hit.point.z) + 0.5f);
GetComponent<MeshRenderer>().enabled = true;
}
}
if (Input.GetMouseButtonUp(0))
{
ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, out hit, Mathf.Infinity, levelLayer))
if (hit.collider.tag == "Replaceable")
{
placePosition = new Vector2I((int)transform.position.x, (int)transform.position.z);
EditorManager.map.SetEmpty(placePosition);
EditorManager.map.BrushTile(EditorManager.map.TypeToObject((Tile.tileType)tileType), placePosition, (Tile.tileType)tileType);
GetComponent<MeshRenderer>().enabled = false;
gameObject.SetActive(false);
}
}
}
}
Everything up until any Physics.Raycast line works. The idea is that there is a ray casted from the position your finger is at when touching the screen.