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;
}
}
}