我似乎找不到答案,我相信现在是不可能的。
我有一个收集游戏对象的玩家,当游戏对象被收集时,它们成为玩家的孩子。所有游戏对象都具有不同质量的刚体,但重复的游戏对象具有相同的质量。
当收集游戏对象时,玩家会变得越来越多。
我想要做的是,当玩家达到一定的质量并收集另一个游戏对象时,我希望质量最小的游戏对象设置为不活动。
我已经得到了这个:
Component[] objects = GetComponentsInChildren(typeof(Rigidbody), false);
foreach (Rigidbody joint in objects)
{
float smallest = Mathf.Min(joint.mass);
if (smallest <= mass / 100 && joint.gameObject.activeInHierarchy)
{
int i = 0;
bool plus = false;
while (i < transform.childCount)
{
if (transform.GetChild(i).gameObject.activeInHierarchy && plus == false)
{
transform.GetChild(i).gameObject.SetActive(false);
Debug.Log("disabled");
plus = true;
}
i++;
}
}
}这会使玩家的第一个子游戏对象在达到一定质量后处于非活动状态。
但这并不是我真正想要的,我想将具有最小质量的游戏对象设置为非活动状态,但我不能将"float smallest = Mathf.Min(joint.mass);“转换回游戏对象。
这是可能实现的,还是根本不可能实现?
发布于 2017-02-02 02:04:40
当然也有可能是我的朋友
using System.Linq // < --- at top of script
List<Rigidbody> objects = GetComponentsInChildren<Rigidbody>(false)
.OrderBy(i => i.mass)
.ToList();
Rigidbody smallest = objects.FirstOrDefault();https://stackoverflow.com/questions/41986550
复制相似问题