Search code examples
unity-game-engineunityscript

new tag not working


im having trouble figuring out whats wrong with this code, ive added a new tag name 'light' and i cant get it to respond when i put it on the object, ive used this very similar code in the same scene but the tag has changed to ammo, or health. if i change the tag in the code to one of the older ones it responds but 'light' no response doesn't do anything. ive checked trigger is set on the cube, its essentially identical to the objects in my scene already apart from the tag being changed nd nothing. im using a free unity version 4.6.

 var amplitude : float = 10.0;

 function Start() {

 }

 function OnTriggerEnter (l : Collider)
 {
     if(l.tag == "light")
     {
         amplitude = 100;
     }
 }

Solution

  • When you use a float, you have to add the letter f to the end of the value, to tell the computer that it is a float.
    You have to change var amplitude : float = 10.0; to var amplitude : float = 10.0f;, and change amplitude = 100; to amplitude = 100f;.
    If you don't add the f, the computer will change 10.0 to a double, and 100 to an int.