2 回答

TA貢獻(xiàn)2021條經(jīng)驗(yàn) 獲得超8個(gè)贊
您創(chuàng)建一個(gè) BulletManager.cs(將其附加到始終處于活動(dòng)狀態(tài)的對(duì)象或空游戲?qū)ο螅?/p>
public static BulletManager instance;
private void Awake
{
if ( instance == null ) //this creates a Singleton so you can access it directly from everywhere, won't go deep into explaining how it works exactly
{
instance = this;
}
else
{
Destroy (gameObject);
}
}
public int machinegunDmg; //set the initial values in the editor
public int shotgunDmg;
public int skeletonDmg;
現(xiàn)在用適當(dāng)?shù)臉?biāo)簽標(biāo)記所有預(yù)制件,假設(shè)您為機(jī)槍射彈預(yù)制件使用“MachineGunProj”標(biāo)簽。
您附加到所有預(yù)制件的相同腳本應(yīng)該會(huì)受到該 BulletManager 腳本的損壞,具體取決于您實(shí)例化的預(yù)制件。
private int DamageOnHit;
//this will get called everytime you instantiate a new prefab that holds this script; it will check for its own tag and depending on it will set the damage in this script to be equal to the appropriate value from BulletManager.cs
private void Start
{
if(this.gameObject.CompareTag("MachineGunProj"))
{
this.DamageOnHit = BulletManager.instance.machinegunDmg;
}
else if(this.gameObject.CompareTag("ShotgunProj"))
{
this.DamageOnHit = BulletManager.instance.shotgunDmg;
}
//else if -- do the same for every prefab you have
}
至于升級(jí),您需要更改 BulletManager.cs 中的值。例如:
public void UpgradeMachineGun()
{
BulletManager.instance.machinegunDmg++; //next time you spawn a machinegun prefab it will take the upgraded value
}
*我直接在這里編寫(xiě)了上面的代碼,沒(méi)有任何文本編輯器或其他任何東西的幫助,所以我可能錯(cuò)過(guò)了一些東西,但總的來(lái)說(shuō),這是它應(yīng)該如何工作的想法。如果有什么不起作用,我將非常樂(lè)意為您提供進(jìn)一步的幫助:)

TA貢獻(xiàn)1797條經(jīng)驗(yàn) 獲得超6個(gè)贊
兩種選擇:
在射彈的
DamageOnHit
每個(gè)實(shí)例上設(shè)置每次
Instantiate
創(chuàng)建新的射彈預(yù)制件時(shí),獲取其Projectile
組件并將其設(shè)置DamageOnHit
為所需的值。
。每次游戲重新啟動(dòng)時(shí),復(fù)制每個(gè)預(yù)制資源
我們將它們稱(chēng)為“ProjectileShotgunProto”和“ProjectileSkeletonProto”。
Instantiate(ProjectileShotgunProto)
當(dāng)玩家射擊時(shí)您將調(diào)用它們,而不是實(shí)例化您的原始預(yù)制件。
無(wú)論如何,請(qǐng)勿更改代碼中的原始預(yù)制資源,否則會(huì)導(dǎo)致問(wèn)題。
- 2 回答
- 0 關(guān)注
- 145 瀏覽
添加回答
舉報(bào)