You need to set the type of your variables, it isn’t crucial to the problem but important for the future.
var addmat1 : int = 5;
You’re not using the variable returned from the collision.
function OnTriggerEnter (Collision: Collider)
//Should be
function OnTriggerEnter (other : Collider)
//As this is the data from the other colliding object, not the collision
//Then use
if (other.GameObject == collide1) {
//As garner stated do not end the if-statements with semicolon
}
You might as well use the colliders as variables instead of calling the GameObjects if you don’t plan on using the reference later.
var collide1 : Collider;
if (other == collide1) {}
I recommend you to start using #pragma strict in the top of your scripting documents to disable dynamic scripting, you will have a much easier pipeline for errors, and the main reason, much faster code.
Although when creating pickups it’s usually better to let the pickups have values that passes on to a handler. So if you’d create a pickup-script and attached it to the GameObject, then you’ll be able to give it different amounts of values, for instance a pile of gold is more worth than a single gold coin but increases the same value.
You could start off with an enum setting the type of pickup, then give that particular pickup a value.
enum PICKUP {
Nails,
Wood,
Metal,
Misc
}
//From the inspector you can switch this and make the object into a prefab
var pickupType : PICKUP = PICKUP.Nails;
var amount : int = 1;
Now when the collision occurs you can ask the colliding object what it is and how much it is worth.
function OnTriggerEnter (other : Collider) {
if (!other.CompareTag("Pickup")) return; //Make sure that this is a pickup else exit (needs a tag set in the Inspector)
var pickupScript : PickupScript = other.GetComponent(PickupScript); //Get the script from the colliding object
DoSomething(pickupScript.pickupType, pickupScript.amount); //Send the type and amount into a function
}
//Take care of the amount that should get stored into corresponding variable
function DoSomething (type : PICKUP, amount : int) {
switch (type) {
case PICKUP.Nails: mat1+=amount; break;
case PICKUP.Wood: mat2+=amount; break;
case PICKUP.Metal: mat3+=amount; break;
case PICKUP.Misc: mat4+=amount; break;
}
}