add pills to heal self
This commit is contained in:
@@ -4,7 +4,7 @@ using UnityEngine;
|
||||
|
||||
public class BlockManager : MonoBehaviour
|
||||
{
|
||||
public enum BlockType {None, Barricade, Door, Wood, Ammo, FireCamp};
|
||||
public enum BlockType {None, Barricade, Door, Wood, Ammo, FireCamp, Pills};
|
||||
public BlockType blockType = BlockType.None;
|
||||
public float health = 100;
|
||||
public float healthRate = 5;
|
||||
@@ -13,6 +13,9 @@ public class BlockManager : MonoBehaviour
|
||||
private PlayerManager player;
|
||||
private bool action = false;
|
||||
public List<GameObject> amountModels = new List<GameObject>();
|
||||
public GameObject pills;
|
||||
public GameObject prefabPills;
|
||||
public Vector3 spawnPillsPoint;
|
||||
|
||||
public AudioSource audioSource = new AudioSource();
|
||||
public AudioClip doorSound;
|
||||
@@ -33,6 +36,10 @@ public class BlockManager : MonoBehaviour
|
||||
{
|
||||
healthTime = healthRate;
|
||||
}
|
||||
else if (blockType == BlockType.Pills)
|
||||
{
|
||||
healthTime = healthRate;
|
||||
}
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
@@ -55,6 +62,13 @@ public class BlockManager : MonoBehaviour
|
||||
healthTime = healthRate + Time.time;
|
||||
}
|
||||
}
|
||||
else if (blockType == BlockType.Pills)
|
||||
{
|
||||
if (pills == null && healthTime < Time.time) {
|
||||
pills = Instantiate(prefabPills, spawnPillsPoint, prefabPills.transform.rotation);
|
||||
this.GetComponent<BoxCollider>().enabled = true;
|
||||
}
|
||||
}
|
||||
viewHealthAs();
|
||||
}
|
||||
|
||||
@@ -132,6 +146,22 @@ public class BlockManager : MonoBehaviour
|
||||
player.ammo += (player.ammo <= 40 ? 10 : (50 - player.ammo));
|
||||
}
|
||||
}
|
||||
else if (blockType == BlockType.Pills)
|
||||
{
|
||||
if (pills != null && player.actualHealth != player.health) {
|
||||
if (player.actualHealth <= player.health - health)
|
||||
{
|
||||
player.actualHealth += health;
|
||||
}
|
||||
else
|
||||
{
|
||||
player.actualHealth = player.health;
|
||||
}
|
||||
Destroy(pills);
|
||||
this.GetComponent<BoxCollider>().enabled = false;
|
||||
healthTime = healthRate + Time.time;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SpikeHit()
|
||||
|
Reference in New Issue
Block a user