Hello. I was wondering how would I make particles show when I hit an animal, tree, and ore. I am new to unity and want to know how to do this. If you guys could help me I would appreciate that.
public float maxHealth, maxThirst, maxHunger;
public float thirstIncreaseRate, hungerIncreaseRate;
private float health, thirst, hunger;
public bool dead;
public GameObject player;
public float damage;
public bool weaponEquipped;
public bool toolEquipped;
public static bool triggeringWithAI;
public static GameObject triggeringAI;
public static bool triggeringWithTree;
public static GameObject treeObject;
public static bool triggeringWithOre;
public static GameObject oreObject;
[Header("UI Components")]
public Text healthText;
public Text thirstText;
public Text foodText;
public void Start()
{
health = maxHealth;
}
public void Update()
{
healthText.text = health.ToString();
thirstText.text = thirst.ToString();
foodText.text = hunger.ToString();
if (!dead)
{
hunger += hungerIncreaseRate * Time.deltaTime;
thirst += thirstIncreaseRate * Time.deltaTime;
}
if (thirst >= maxThirst)
Die();
if (hunger >= maxHunger)
Die();
//print(thirst);
//print(hunger);
//print(health);
//detecting and killing ai
if (triggeringWithAI == true && triggeringAI)
{
if (Input.GetMouseButtonDown(0))
{
Attack(triggeringAI);
}
}
if (!triggeringAI)
triggeringWithAI = false;
//tree chopping
if(triggeringWithTree == true && treeObject)
{
if (Input.GetMouseButtonDown(0))
Attack(treeObject);
}
//ore mining
if(triggeringWithOre == true && oreObject)
{
if (Input.GetMouseButtonDown(0))
Attack(oreObject);
}
}
public void Attack(GameObject target)
{
if (target.tag == "Animal" && weaponEquipped)
{
Animal animal = target.GetComponent<Animal>();
animal.health -= damage;
}
if (target.tag == "Tree" && weaponEquipped)
{
TreeChopping tree = target.GetComponent<TreeChopping>();
tree.health -= damage;
}
if (target.tag == "Ore" && toolEquipped)
{
OreMining ore = target.GetComponent<OreMining>();
ore.health -= damage;
}
}
public void Die()
{
dead = true;
Destroy(player);
print("You died.");
}
public void Drink(float decreaseRate)
{
thirst -= decreaseRate;
}
public void Eat(float decreaseRate)
{
hunger -= decreaseRate;
}
public void OnTriggerStay(Collider other)
{
if (other.tag == "Tree")
{
triggeringWithTree = true;
treeObject = other.gameObject;
}
if (other.tag == "Ore")
{
triggeringWithOre = true;
oreObject = other.gameObject;
}
}
public void OnTriggerEnter(Collider other)
{
if (other.tag == "Animal")
{
triggeringAI = other.gameObject;
triggeringWithAI = true;
}
}
public void OnTriggerExit(Collider other)
{
if (other.tag == "Animal")
{
triggeringAI = null;
triggeringWithAI = false;
}
}