I made an script to place object in the position of the mouse if the object where you are clicking has an specific tag. but the Raycast ray goes through object and it never hits. Here is the script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BlueHelmets : MonoBehaviour
{
public GameObject prefab;
private GameObject handler;
RaycastHit hit;
public float Reach = 2.0f;
void Update()
{
if (Input.GetMouseButtonDown(0))
{
Ray rayCast = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(rayCast, out hit, Reach))
{
Debug.DrawLine(rayCast.origin, hit.point);
if (hit.transform.CompareTag("WarSite"))
{
Debug.Log("Raycast hit war site");
handler = Instantiate(prefab, hit.point, Quaternion.identity) as GameObject;
}
else
{
Debug.LogWarning("Raycast hit " + hit.transform.tag);
}
}
else
{
Debug.LogError("No object hit");
Debug.DrawRay(rayCast.origin, rayCast.direction * 1000);
}
}
}
}