控制摄像机发射光线销毁物体
using UnityEngine;
using System.Collections;
public class guangxian : MonoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
float dirX = Input.GetAxis ("Mouse X");
float dirY = Input.GetAxis ("Mouse Y");
transform.Rotate (dirX, -dirY, 0);
CheckForRayCastHit ();
}
void CheckForRayCastHit()
{
RaycastHit hit;
//第一个参数是光线开始的位置,第二个参数是光线行进方向,第三个是光线行进距离
if (Physics.Raycast (transform.position, transform.forward, out hit)) {
print ("jjjjjjjjjjjj" + hit.collider.gameObject.name);
Destroy (hit.collider.gameObject);
}
}
}