纳金网
标题: 被瞄准的对象显示血条或子物体(原理) [打印本页]
作者: 烟雨 时间: 2015-8-30 00:17
标题: 被瞄准的对象显示血条或子物体(原理)
如图 鼠标放在终点的cube显示出 Sphere;
这个可以用来做瞄准物体显示血条,在端游中经常看见的功能
代码如下:
- using UnityEngine;
- using System.Collections;
- public class CubeSph : MonoBehaviour
- {
- public GameObject sph;
- // Use this for initialization
- void Start()
- {
- sph = transform.Find("Sphere").gameObject;
- sph.SetActive(false);
- }
- // Update is called once per frame
- void Update()
- {
- Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
- RaycastHit hit;
- if (Physics.Raycast(ray, out hit))
- {
- print("hit.name=" + hit.transform.tag);
- if (hit.transform.tag == "enemy") //把cube的tag设置为 enemy
- {
- sph = hit.transform.FindChild("Sphere").gameObject;
- sph.SetActive(true);
- }
- }
- else
- {
- print("没有");
- sph.SetActive(false);
- }
- }
- }
复制代码
欢迎光临 纳金网 (http://go.narkii.com/club/) |
Powered by Discuz! X2.5 |