下面的C#代码以不同的概率生成游戏对象,但我用JavaScript编写了大部分游戏逻辑。下面的代码在Javascript中是什么?帮助将不胜感激。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SpawnerScript05 : MonoBehaviour {
public Spawn04[] spheres;
void Start () {
}
void Update () {
if (Input.GetKeyDown (KeyCode.Space)) SpawnObjects ();
}
void SpawnObjects() {
int i = Random.Range (0, 100);
for (int j = 0; j < spheres.Length; j++) {
if (i >= spheres [j].minProbabilityRange && i <= spheres [j].maxProbabilityRange) {
Instantiate (spheres [j].spawnObject, transform.position, transform.rotation);
break;
}
}
}
}
[System.Serializable]
public class Spawn04 {
public GameObject spawnObject;
public int minProbabilityRange = 0;
public int maxProbabilityRange = 0;
}
应该是这样的:
import UnityEngine;
import System.Collections;
import System.Collections.Generic;
class SpawnerScript05 extends MonoBehaviour {
var spheres : Spawn04[];
function Start() {
}
function Update() {
if (Input.GetKeyDown(KeyCode.Space)) SpawnObjects();
}
void SpawnObjects() {
var i: int;
i = Random.Range(0, 100);
for (var j = 0; j < spheres.Length; j++) {
if (i >= spheres[j].minProbabilityRange && i <= spheres[j].maxProbabilityRange) {
Instantiate(spheres[j].spawnObject, transform.position, transform.rotation);
break;
}
}
}
class Spawn04 {
var spawnObject : GameObject;
var minProbabilityRange : int = 0;
var maxProbabilityRange : int = 0;
}
}