using UnityEngine;
using System.Collections;
public class ray : MonoBehaviour {
private Camera _camera;
public GUISkin MySkin;
public GameObject paodan;
// Use this for initialization
void Start () {
_camera = GetComponent<Camera>();
}
// Update is called once per frame
void Update () {
if(Input.GetMouseButtonDown(0)){
Vector3 point = new Vector3(_camera.pixelWidth/2,_camera.pixelHeight/2,0);
Ray ray = _camera.ScreenPointToRay(point);
RaycastHit hit;
if(Physics.Raycast(ray,out hit)){
GameObject hitobject = hit.transform.gameObject;
ReactiveTarget target = hitobject.GetComponent<ReactiveTarget>();
if(target != null){
Debug.Log("Target hit!");
target.ReactiveToHit();
Fenshu fenshu=GetComponent<Fenshu>();
fenshu.setCount();
}
else{
Debug.Log("hit"+hit.point);
StartCoroutine(SphereIndicator(hit.point));
}
}
}
}
private IEnumerator SphereIndicator(Vector3 pos){
GameObject sphere = Instantiate(paodan) as GameObject;
sphere.transform.position = pos;
yield return new WaitForSeconds(2);
Destroy(sphere);
}
void OnGUI(){
GUI.skin = MySkin;
float size = 30f;
float posX = _camera.pixelWidth/2 - size/2;
float posY = _camera.pixelHeight/2 - size/2;
GUI.Label(new Rect(posX,posY,size,size),"*");
}
}
第一人称<ray>
最新推荐文章于 2024-12-11 19:25:30 发布