查找播放器和相机之间的所有对象 [英] Find all objects between player and camera
本文介绍了查找播放器和相机之间的所有对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用相机的正投影来跟随玩家.我想在玩家和相机之间找到所有游戏对象,以便可以更改不透明度,以便在遮挡相机视图时它们是部分透明的.我读过有关光线投射的信息,但似乎只能在播放器和相机之间提供第一个对象.有什么方法可以做到这一点?
I am using an orthographic projection for camera to follow a player. I would like to find all gameobjects between the player and the camera so I can change the opacity so they are partially transparent while blocking the camera's view. I read about raycasting, but it seems it would give only the first object between the player and camera. What approaches are there to accomplish this?
推荐答案
只需使用物理. RaycastAll 像这样:
public class CameraScript : MonoBehaviour
{
//Attach this script to the camera//
public GameObject player;
void Update()
{
float dist = Vector3.Distance(transform.Position, player.transform.position);
RaycastHit[] hits = hits = Physics.RaycastAll(transform.position,
transform.forward, 100.0F);
foreach (RaycastHit h in hits)
{
//Change the opacity of the of each object to semitransparent.
}
}
}
这篇关于查找播放器和相机之间的所有对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文