It only works when I call it from another script. But I don't want that. Been figuring around with it but it just won't work. Any idea why or what's wrong with my code? Code (CSharp): using System.Collections; using System.Collections.Generic; using UnityEngine; public class Deathscript : MonoBehaviour { public bool Alive; public Rigidbody[] rb; private int j; // Use this for initialization void Start() { Alive = true; for (j = 0; j < 11; j++) { rb[j].isKinematic = true; } } void OnCollisionEnter(Collision collision) { if (collision.gameObject.name == "Weapon") { Alive = false; for (j = 0; j < 11; j++) { rb[j].isKinematic = false; } } } private void LateUpdate() { if (Alive == false) { GetComponent<Animator>().enabled = false; } } }
put a debug line before if (collision.gameObject.name == "Weapon") and first make sure it's not being called. If it is being called, does the weapon have child objects that are not named "Weapon"?
Hi thanks for the reply. But still does not work. Tried the debugging and it is not called at all until collided. Once one character collided to the "Weapon" object, it will stop all the animations from other different characters. Still couldn't figure out why. I even tried adding in the gameobject to specify the character in this code but still no vail. Code (CSharp): using System.Collections; using System.Collections.Generic; using UnityEngine; public class Deathscript : MonoBehaviour { public GameObject student; public static bool Alive; public Rigidbody[] rb; private int j; // Use this for initialization void Start() { Alive = true; for (j = 0; j < 11; j++) { rb[j].isKinematic = true; } } void OnCollisionEnter(Collision collision) { if (collision.gameObject.name == "Weapon") { Alive = false; for (j = 0; j < 11; j++) { rb[j].isKinematic = false; } } } void Update() { if (Alive == false) { student.GetComponent<Animator>().enabled = false; } } }
And another thing I found when I put debug at the line: Code (CSharp): Debug.Log(student.GetComponent<Animator>().enabled = false); It shows in console the numbers beside the error keeps going up. What could that be?
Ok nvm I solve the problem due to a small mistake =_=||. I didn't notice this line was public: Code (CSharp): public static bool Alive; And changed to: Code (CSharp): private bool Alive; works.