「マウスで選択したオブジェクト」を「ボタンを押すことで破壊」する。
*基本スクリプト
using UnityEngine;
using System.Collections;
public class ray : MonoBehaviour {
public GameObject effectPrefab;
private GameObject target;
void Start () {
}
void Update () {
/*
Vector3 fwd = transform.TransformDirection(Vector3.forward);
if(Physics.Raycast(transform.position, fwd, 10)){
print("there is somthing in front of the object.");
}
*/
if(Input.GetButtonDown("Jump")){
RaycastHit hit;
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if(Physics.Raycast(ray, out hit)){
target = hit.collider.gameObject;
if(target.gameObject.CompareTag("Enemy")){
Destroy(target, 0.1f);
Instantiate(effectPrefab, target.transform.position, Quaternion.identity);
}
/*
if(hit.collider != null){
Destroy(target, 0.1f);
Instantiate(effectPrefab, target.transform.position, Quaternion.identity);
//hit.collider.enabled = false;
}
print("there is somthing.");
*/
}
}
}
}

