A new instance of a script being created when not supposed to.

I have this bit of code here that subtracts from the enemies health and causes it’s speed to be halved for a second.

void OnTriggerEnter (Collider other) {
	if (other.CompareTag ("Enemy")) {
		Enemy humanoid = other.GetComponentInParent<Enemy> ();//Enemy.cs is attatched to the enemy and has variables set
		humanoid.UpdateHealth (-dmg);//Adds sent variable to health
		humanoid.Stutter (stutterTime, stutterSpeed);//Stutters humanoid
		humanoid.DebugHumanoid ();//Simply prints out all the humanoid variables
        //All three methods called here are contained in Humanoid.cs that Enemy.cs inherits from
}//Void OnCollisionEnter (Collider)

But for some reason it’s not editing the enemies humanoid variables, but creating a completely new instance of Enemy.cs and using that.

I’ve been stuck on this for hours now. (Also sorry for the poor explanation, I’ve been trying to find out a way to explain this for a half an hour now)


I would say by calling it Enemy Humanoid = getcomp… etc you are instancing another class…

try this:
gameObject humanoid = other.getcomp… etc
or even:
var humanoid = other.getcomp etc

Hope that works for you.