Variable doesn't change when box hit trigger area

I’m trying to make a trigger area change value after a specific object (cube) enters the area (cube trigger), but when I move the cube to the area, the “debug” value doesn’t change (from 1 to 2). What am I doing wrong?

var other : GameObject;

//var fuel_points : int = 100;

var debug : int = 1;

function OnCollisionEnter (other : Collision) {


 debug ++;


   //fuel_points = other.GetComponent(fuel_points);

 			//fuel_points += 10;


//else(game do blablablabla)

// 	Destroy(other.gameObject);    



gameObject.tag is the tag of the object to which this script is attached, and you should use OnTriggerEnter instead:

function OnTriggerEnter (other : Collider) {
  // verify whether the tag of the object entering the trigger is "other":
  if (other.tag=="other"){
    debug ++; // if so, increment debug

NOTE: This script is comparing the entering object’s tag to “other” - is this what you actually want to do? Usually the player is tagged “Player”, but of course you can use any tag you want - provided that you have registered this tag previously.

Edit 2**

Based on your response I’m gathering that what you are doing is that your collision script is attached to the area, and it is listening for collision of these cubes that will give it fuel. toward that end I would propose the following restructure: Create a new Tag called “Fuel” assign the cubes this new tag, then swap out your current code for the following:

var debug : int = 1;

function OnTriggerEnter(other : Collider)
    if(other.tag == "Fuel")

Aldonaletto’s response is a little more concise and technically more correct, I’d recommend his approach.


Okay, actually I just took a second look and here are the two things I’m seeing. As I mentioned in my comment, you are looking for an “other” tag, please make sure you are not confusing this with your other: Collision variable. Secondly, you are not checking the collided object but rather the object the script is on, try changing




and as mentioned, make sure that you have an “other” tag on the cube

Alright, thank you for your answers but this is how it works:

  1. Picking up a cube with a certain script (the one I posted) and releasing it into the trigger area.
  2. The cube is a catalyst that will increase the int variable

Problem is, when it collides it doesn’t change, yes I’ve selected the correct “other” and the pickup is same target, but is there a chance that they are colliding with each other? It doesn’t show up any errors while doing this.