Compiler error while trying to access a Collider's script.

I have this script, MintScript.cs:

using UnityEngine;
using System.Collections;

public class MintScript : MonoBehaviour 
	public int type;

	void OnTriggerEnter(Collider collision)


Attached to that Collider (the player), I have a script called Collectables.cs.

When I try to compile, I get this error:

Assets/Scripts/MintScript.cs(15,67): error CS1061: Type UnityEngine.Component' does not contain a definition for addMint’ and no extension method addMint' of type UnityEngine.Component’ could be found (are you missing a using directive or an assembly reference?)

Any idea why this is happening? The Collider’s name matches my character’s object name, tested by that log statement, and that character definitely has the Collectables script attached. Both are C# files.

Don’t use strings in GetComponent.



(collision.gameObject.GetComponent(typeof(Collectables)) as Collectables).addMint();

As the error says, Component does not contain addMint, so you need to cast to the correct type.