GetComponent error

I’m not sure what I’m doing wrong, I tried googling but that wasn’t much help. It’s probably obvious but I just can’t figure out what I’m doing wrong. The last line in the function is the problem. Any help is appreciated :slight_smile:

Here is the error: error CS0309: The type UnityEngine.Material' must be convertible to UnityEngine.Component’ in order to use it as parameter T' in the generic type or method UnityEngine.GameObject.GetComponent()

	void Thing(string name, int damage, int health, float walkSpeed,GameObject gameObj){ = name;
		this.damage = damage; = health;
		this.walkSpeed = walkSpeed;
		this.gameObj = gameObj;
		color = new Color(Random.Range (0, 255),Random.Range (0, 255),Random.Range (0, 255));
		material = gameObj.GetComponent<Material>();

GetComponent shouldn’t use. And rename variable material as, for example, myMat. Instead write:

 myMat = gameObj.renderer.material;

A Material isn’t a component and therefore can’t be used with GetComponent. It’s an object that’s used in some components such as MeshRenderer.