my script is not working when i clic the gameObject after disabling and enabling isKinematic, i have tried with Sleep(), WakeUp() and detectCollisions and none of these are working
the idea is that when health reaches 0 the enemy ragdolls and then stops, and after that i should be able to clic on it to add items to the inventory
here is my code and a video
public int health = 200;
public string Enemyname = "";
public InventoryItem leather;
public InventoryItem meat;
public int hits = 5;
Rigidbody rb;
void Start()
{
rb = GetComponent<Rigidbody>();
}
void Death()
{
rb.isKinematic = false;
//rb.detectCollisions = true;
Invoke("enableKinematic", 1);
}
public void takeDamage(int amount)
{
Debug.Log("caca");
if (health <= 0)
{
if (hits >= 1)
{
if (Enemyname == "Pig")
{
int random = Random.Range(1, 3);
if (random == 1)
Inventory.instance.Add(leather, 1);
else
Inventory.instance.Add(meat, 1);
hits--;
if (hits <= 0)
{
Destroy(gameObject);
}
}
}
}
health -= amount;
if (health <= 0)
Death();
}
void enableKinematic()
{
rb.isKinematic = true;
//rb.detectCollisions = false;
rb.WakeUp();
}