- Home /
problem solved
Script not working after changing isKinematic
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();
}
Answer by nicopucho · Sep 23, 2017 at 03:49 PM
nvm i solved it, the raycast was hitting my character and not the enemy, weird cause it worked with trees and other items
Follow this Question
Related Questions
Rigidbody not responding after toggling isKinematic 2 Answers
Iskinematic: how does it work? 1 Answer
Why do I get OnTriggerExit upon collision when a rigidbody is kinematic? (example) 3 Answers
How can I make my coins move without knocking my player around? 2 Answers
How to re-center a Rigidbody isKinematic object after adding force to it? 2 Answers