using
UnityEngine;
using
System.Collections;
public
class
UIControl3D : MonoBehaviour {
public
Camera myCamera;
private
float
time = 0;
public
MeshRenderer target_on;
public
MeshRenderer target_off;
public
ParticleSystem myExplosion;
// Use this for initialization
void
Start () {
}
// Update is called once per frame
void
Update () {
CheckTargeted();
}
void
CheckTargeted()
{
// 分屏,宽度在1/2屏幕居中
Ray ray = myCamera.ScreenPointToRay(
new
Vector3( Screen.width / 4, Screen.height / 2));
RaycastHit hits;
// 发出射线
if
( Physics.Raycast(ray,
out
hits, 5000))
{
Debug.Log(hits.collider.name);
if
(hits.collider.name ==
"Cube"
)
{
time += 1 * Time.deltaTime;
target_on.enabled =
true
;
target_off.enabled =
false
;
if
(time >= 1.5f)
{
this
.myExplosion.Play();
time += Time.deltaTime;
}
if
(time >= 2)
{
time = 0;
this
.myExplosion.Stop();
}
}
}
else
{
// 重置场景
time = 0;
target_on.enabled =
false
;
target_off.enabled =
true
;
}
}
}