当前具有以下代码可对列表项进行随机排序:
if(Input.GetKeyDown("c"))
{
prefabInstanceClone = Instantiate(prefabInstance, transform.position, Quaternion.identity) as GameObject;
}
我希望其中一个元素始终是最后一个。怎么做?
答案 0 :(得分:0)
array = ["a", "b", "the last", "c", "d"];
array.sort(function(a, b) {
return (b == "the last") ? -1 :
((a == "the last") ? 1 :
(0.5 - Math.random()));
});
document.write(array);
工作原理: