I have the following two scripts. One will disable the script, while the other one wont. The print statements will print for both, meaning the function is being executed, but only one of them (the armbreak script) will disable the script. There are no errors printed in the console. All the scripts are in the same folder and are all in C#. Anyone have any idea what could be happening?
I would check to make sure the Enemy public variable is pointing to the enemy you think it is, if you have more than one.
One easy thing to add is to name all your enemies differently (enemy1, etc.) and then in the debug statement, print out the .name field of yourself (just .name) and of the enemy (Enemy.name) to get more info on what might be happening.
And PLEASE… use the code formatting features, basically square brackets with the word code in them… see the forum help.
Unfortunately there is only one enemy, so there is no question about whether or not i am referencing the right one. The weird thing however, is that im using identical lines of code, they are being executed, but nothing is happening.
Thanks for your help though, and ill use the forum code format, i’ll admit thats pretty hideous to read.
using UnityEngine;
using System.Collections;
public class armbreak : MonoBehaviour {
public GameObject Enemy;
void OnJointBreak(float breakForce)
{
print (breakForce);
Enemy.GetComponent<EnemyFire> ().enabled = false;
}
}
Heres the script that doesn’t work:
using UnityEngine;
using System.Collections;
public class HandPistolBReak : MonoBehaviour {
public GameObject Enemy;
void OnJointBreak(float breakForce)
{
Enemy.GetComponent<EnemyFire> ().enabled = false;
print ("broken with" + breakForce);
}
}
There was another script that was consistently re-enabling . This script would be disabled if the enemy fell over or hit the ground. When the gun was pulled from the enemies hand (HandPistolBreak), the enemy would usually not fall over, and thus the other script would never be disabled, and the script would never be disabled. However, with the case of the Script, if this script needed to be called, it usually meant the enemy had touched the ground, because its arms got ripped off and thats a pretty big thing, youre gonna fall over if your arms get ripped off. So because he fell over, he disabled the other script, which means could be disabled, which explains why identical lines of code yield different outputs.