I’m fairly new to Unity, but I’m having an issue where I have the following script/class heirarchy:
public class Weapon : MonoBehaviour { /* snip */ }
public class MachineGun : Weapon { /* snip */ }
public class CharacterShoot : MonoBehaviour
{
public GameObject currentWeapon;
private Weapon weapon;
/* snip */
}
All of these script classes are in separate files, and the files are named correctly.
The CharacterShoot script is a component of a character that is currently in the scene.
I have a prefab called “MachineGun” that has only the “MachineGun” script as a component with some of the default values overridden.
‘currentWeapon’ is meant to be an instance of a prefab that I’ve created by dragging the MachineGun prefab from the Project tab into the ‘currentWeapon’ field in the CharacterShoot component of the instanced character.
Finally, to the problem: none of the standard script functions appear to be called by Unity on the MachineGun script. I’m outputting Debug messages to the log at the top of the Awake, Start and Update functions, for both the derived MachineGun class and the base Weapon class, and none of them are showing. The only messages that are showing are from functions that I call myself, explicitly from within the CharacterShoot script when I attempt to fire off a projectile.
But, without changing anything, when I drag an instance of the MachineGun prefab directly into the scene and run it, I get all the Awake, Start and Update messages as I would expect.
Edit:: Okay, it has nothing to do with the MachineGun script. I replaced the MachineGun script component inside the MachineGun prefab with the base Weapon script, and the same problem still happens.