Help! OnTriggerEnter isn't working.

Here’s my onTriggerEnter’s javascript code:

function OnTriggerEnter (other : Collider) {
if (other.gameObject.CompareTag ("BuildGrist")) {
    //Destroy grist object and collect grist
    pickingUpGrist = true;
    GristType = "BlueGrist";
    Destroy(other.gameObject);
}
if (other.gameObject.CompareTag ("AmethystGrist")) {
    //Destroy grist object and collect grist
    pickingUpGrist = true;
    GristType = "PurpleGrist";
    Destroy(other.gameObject);
}
if (other.gameObject.CompareTag ("CaulkGrist")) {
    //Destroy grist object and collect grist
    pickingUpGrist = true;
    GristType = "BlackGrist";
    Destroy(other.gameObject);
}
if (other.gameObject.CompareTag ("MercuryGrist")) {
    //Destroy grist object and collect grist
    pickingUpGrist = true;
    GristType = "GreyGrist";
    Destroy(other.gameObject);
}
if (other.gameObject.CompareTag ("CobaltGrist")) {
    //Destroy grist object and collect grist
    pickingUpGrist = true;
    GristType = "DBlueGrist";
    Destroy(other.gameObject);
}
if (other.gameObject.CompareTag ("ChalkGrist")) {
    //Destroy grist object and collect grist
    pickingUpGrist = true;
    GristType = "WhiteGrist";
    Destroy(other.gameObject);
}
}

Unity keeps saying this: “Assets/Standard Assets/Scripts/Player Inventory/GristAmount.js(20,10): BCE0044: expecting (, found ‘OnTriggerEnter’.” Could someone please elaborate to me how to use onTriggerEnter or why this code isn’t working?

EDIT: My function is on Line 20 of the source file.

EDIT: FULL SCRIPT:

#pragma strict

var BGristAmount = 1000;
var PGristAmount = 0;
var BlGristAmount = 0;
var GGristAmount = 0;
var DBGristAmount = 0;
var WGristAmount = 0;
var GrabAmount = 0;
var GristType = "";
var pickingUpGrist = false;
var PlayerLevel = 0;

function Start () {

}

function Update () {
GrabAmount = 20 * PlayerLevel;
Collider.OnCollisionEnter() {
if (gameObject.CompareTag ("BuildGrist")) {
    //Destroy grist object and collect grist
    pickingUpGrist = true;
    GristType = "BlueGrist";
    Destroy(other.gameObject);
}
if (gameObject.CompareTag ("AmethystGrist")) {
    //Destroy grist object and collect grist
    pickingUpGrist = true;
    GristType = "PurpleGrist";
    Destroy(other.gameObject);
}
if (gameObject.CompareTag ("CaulkGrist")) {
    //Destroy grist object and collect grist
    pickingUpGrist = true;
    GristType = "BlackGrist";
    Destroy(other.gameObject);
}
if (other.gameObject.CompareTag ("MercuryGrist")) {
    //Destroy grist object and collect grist
    pickingUpGrist = true;
    GristType = "GreyGrist";
    Destroy(other.gameObject);
}
if (other.gameObject.CompareTag ("CobaltGrist")) {
    //Destroy grist object and collect grist
    pickingUpGrist = true;
    GristType = "DBlueGrist";
    Destroy(other.gameObject);
}
if (other.gameObject.CompareTag ("ChalkGrist")) {
    //Destroy grist object and collect grist
    pickingUpGrist = true;
    GristType = "WhiteGrist";
    Destroy(other.gameObject);
}
}

if(pickingUpGrist){
switch(GristType){
case "BlueGrist":
	BGristAmount = BGristAmount + GrabAmount;
	pickingUpGrist = false;
break;
case "PurpleGrist":
	PGristAmount = PGristAmount + GrabAmount;
	pickingUpGrist = false;
break;
case "BlackGrist":
	BlGristAmount = BlGristAmount + GrabAmount;
	pickingUpGrist = false;
break;
case "GreyGrist":
	GGristAmount = GGristAmount + GrabAmount;
	pickingUpGrist = false;
break;
case "DBlueGrist":
	DBGristAmount = DBGristAmount + GrabAmount;
	pickingUpGrist = false;
break;
case "WhiteGrist":
	WGristAmount = WGristAmount + GrabAmount;
	pickingUpGrist = false;
break;
}
}
}

dont do:

other.gameObject.CompareTag

use:

other.gameObject.tag

post your full script because I need to see before the function starts because theres something there

Fix the error, by restructuring your code:

#pragma strict
 
...
 
function Start () {
 
}

function OnTriggerEnter( other : Collider ){
   /* Keep all the if(gameObject.CompareTag)-statement here */	
}
 
function Update () {
	GrabAmount = 20 * PlayerLevel;
	 
	if(pickingUpGrist){
		...
	}
}

I do not know where you learn this from:

function Update() {
   Collider.OnCollisionEnter() {
      ...
   }
}

this snippet is incorrect. You should refer to the documentation if you have any doubts, almost all function in UnityEngine have a working example in the Unity Scripting documentation.


This is irrelevant to the question, but very important to you as a programmer, you have a poor naming habit here, look at this:

var GristType = "";
var pickingUpGrist = false;
var PlayerLevel = 0;

The pickingUpGrist is highlighted differently from GristType and PlayerLevel, you should name your variables according to the style of the pickingUpGrist (capitalize the first letter of all but the first word); your GristType and PlayerLevel is treated as a Class/Function, not variable in the code-formatting.

The style for GristType is not exactly wrong, but it is not recommended. You should adapt to the more common naming convention before your habit screws you up in the future.