所以我有这个脚本,它必须产卵僵尸。僵尸预制有一个带有公共变量Health的脚本。例如,我如何设置每个僵尸的生命值,使每个僵尸比前一个多10点生命值?这是衍生函数(C#):
void SpawnZombie()
{
ZombieClone = Instantiate(ZombiePrefab, RandomSpawnPoint(), Quaternion.identity);//Spawns a copy of ZombiePrefab at SpawnPoint
}它完美的工作,但现在它需要产卵僵尸与一个‘自定义’生命值。我该怎么做呢?
发布于 2017-02-13 19:33:43
使用以下命令:
// Spawns a copy of ZombiePrefab at SpawnPoint
var ZombieClone = Instantiate(ZombiePrefab, RandomSpawnPoint(), Quaternion.identity) as GameObject;
// Retrieve the script from the GameObject
ZombieScript zs = ZombieClone.GetComponent<ZombieScript>();
// Set the desired value of the script
zs.Health = 20;https://stackoverflow.com/questions/42202709
复制相似问题