Following the Book 3.x Development Essentials...

I’m making the surviving island project from the book 3.X Development Essentials but I’m turning crazy about something:
I’m adding the trigger collision detection on the cells, and I have many problems and errors:

function OnTriggerEnter(col : Collider){
if(col.gameObject.tag == “Player”){
col.gameObject.SendMessage(“CellPickup”);
Destroy(gameoObject);
}
}

I wrote this code because it’s copied from the book but there are too many errors:

  • Assets/Standard Assets/Character Controllers/Sources/Scripts/PowerCell.js(8,10): BCE0044: expecting (, found ‘OnTriggerEnter’.
  • Assets/Standard Assets/Character Controllers/Sources/Scripts/PowerCell.js(8,25): BCE0043: Unexpected token: col.
  • Assets/Standard Assets/Character Controllers/Sources/Scripts/PowerCell.js(8,25): BCE0043: Unexpected token: col.
  • Assets/Standard Assets/Character Controllers/Sources/Scripts/PowerCell.js(9,1): BCE0043: Unexpected token: if.
  • Assets/Standard Assets/Character Controllers/Sources/Scripts/PowerCell.js(9,35): UCE0001: ‘;’ expected. Insert a semicolon at the end.
  • Assets/Standard Assets/Character Controllers/Sources/Scripts/PowerCell.js(10,41): BCE0044: expecting :, found ‘;’.

I don’t understand why because I’m a noob of programmation and this it’s my first project.
Could someone help me please :frowning:

“Destroy(gameoObject);” should be “Destroy(gameObject);”. You also have two functions inside of each other. You have OnTriggerEnter() inside of Update(). That’s not allowed. “var rotationSpeed : float = 100.0;” should probably be at the top of the script(Not an error, but it helps with readability)

I edit the comment because I can’t make another one:

thanks greatstprez now there is no error on the script and I can run the game but there is a problem, when I pass over the cell doesn’t disappear do u know why can be that?
my code updated:

#pragma strict
    
    function Start () {
    
    }
    var rotationSpeed : float = 100.0;
    function OnTriggerEnter(col : Collider){
    if(col.gameObject.tag == "Player"){
    col.gameObject.SendMessage("CellPickup");
    Destroy(gameObject);
    }
    }
    function Update () {
    
    
       
    transform.Rotate(Vector3(0,rotationSpeed * Time.deltaTime,0));
    }

Thanks Greatestprez!!!