C# 恢复预置并设置其脚本参数

C# 恢复预置并设置其脚本参数,c#,unity3d,C#,Unity3d,所以我有这个脚本,它必须产生僵尸。 僵尸预置有一个带有公共变量Health的脚本。 如何设置每个僵尸的生命值,例如,给每个僵尸比前一个僵尸多10点生命值? 这是spawn函数(C#): 它工作得非常完美,但现在它需要生成具有“自定义”健康值的僵尸。我该怎么做?使用以下方法: // Spawns a copy of ZombiePrefab at SpawnPoint var ZombieClone = Instantiate(ZombiePrefab, RandomSpawnPoint(), Q

所以我有这个脚本,它必须产生僵尸。 僵尸预置有一个带有公共变量
Health
的脚本。 如何设置每个僵尸的生命值,例如,给每个僵尸比前一个僵尸多10点生命值? 这是spawn函数(C#):

它工作得非常完美,但现在它需要生成具有“自定义”健康值的僵尸。我该怎么做?

使用以下方法:

// 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;
//在繁殖点繁殖僵尸预制的副本
var ZombieClone=实例化(ZombiePrefab,RandomSpawnPoint(),Quaternion.identity)作为游戏对象;
//从游戏对象中检索脚本
ZombieScript zs=ZombieClone.GetComponent();
//设置脚本的所需值
zs.健康=20;
使用以下方法:

// 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;
//在繁殖点繁殖僵尸预制的副本
var ZombieClone=实例化(ZombiePrefab,RandomSpawnPoint(),Quaternion.identity)作为游戏对象;
//从游戏对象中检索脚本
ZombieScript zs=ZombieClone.GetComponent();
//设置脚本的所需值
zs.健康=20;

为什么不在之后设置它<代码>ZombieClone.GetComponent().SetHealth()为什么不在后面设置它<代码>ZombieClone.GetComponent().SetHealth()这会自动带走最后一个繁殖的僵尸吗?因为我每5秒生成一个。这将获取由
实例化
命令创建的僵尸。这会自动获取最后生成的僵尸吗?因为我每5秒生成一个。这将使用
实例化
命令创建的僵尸。