Code
using UnityEngine;
using System.Collections;
public class MouseInteraction : MonoBehaviour {
GameObject minePrefab;
// Use this for initialization
void Start () {
minePrefab = Resources.Load("minePrefab") as GameObject;
}
// Update is called once per frame
void Update () {
Ray ray = Camera.mainCamera.ScreenPointToRay(Input.mousePosition);
RaycastHit hit = new RaycastHit();
if(Input.GetMouseButtonDown(0))
{
if(Physics.Raycast(ray,out hit))
{
//We've hit something
if(hit.collider.gameObject.name.Equals("ground"))
{
//We've hit the ground
CreateMine(hit.point);
}
}
} else if(Input.GetMouseButtonDown(1)) {
if(Physics.Raycast(ray,out hit))
{
//We've hit something
if(hit.collider.gameObject.name.Equals("minePrefab(Clone)"))
{
//We've hit a mine
GameObject.Destroy(hit.collider.gameObject);
}
}
}
}
void CreateMine(Vector3 pos)
{
Instantiate(minePrefab, pos, Quaternion.identity);
}
}