Simple Error?

Hey all,

This might be a really simple error, but I can’t seem to solve it.

var distun = Vector3.Distance(Target.transform.position, transform.position);
		if (distun < 1.5){	
		MeleeAttack(Target);		
		}

So what this does is initiates an attack with the Target (assigned in the inspector as Player Game Object) if they get closer than 1.5 unity meters.

But, I get two errors:
#1- An instance of type ‘UnityEngine.Component’ is required to access non static member ‘transform’.
#2- The best overload for the method ‘zombie_main.MeleeAttack(UnityEngine.Transform)’ is not compatible with the argument list ‘(System.Type)’.

The first error occurs on the first line, and the second error occurs on the third line.

Any suggestions on how to fix this?

hey, the error explains that the variable that you have sent with the function is of other type, so post the all script and I can see what is the real problem…

how are you defining “Target” in the script?

var distun = Vector3.Distance(Target.transform.position, transform.position);

It seems, your variable Target is a GameObject, but Zombie.MeleeAttack needs a Transform.
Using

MeleeAttack(Target.transform);

might solve it…