Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Not compatible with the argument list

Discussion in 'Scripting' started by Alex_Bermann, Feb 5, 2015.

  1. Alex_Bermann

    Alex_Bermann

    Joined:
    Feb 5, 2015
    Posts:
    6
    Hi! I was looking for an answer to this, but without any luck so far...

    I have this code:

    var particleDer : ParticleSystem;
    function Start ()
    {
    }
    function Update ()
    {
    OnTriggerEnter();
    }

    function OnTriggerEnter(col:Collider)
    {
    if (gameObject.tag == "Bubbles")
    {
    particleDer.Play();
    }
    }

    I´m getting this error code: "The best overload for the method ´ScriptName.OnTriggerEnter(UnityEngine.Collider)´ is not compatible with the argument list ´(UnityEngine.GameObject)´.

    Thanks in advance!
     
  2. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,398
    Use code tags please. You shouldn't be calling OnTriggerEnter every frame in Update, so remove that code. OnTriggerEnter runs when a collider enters the trigger.

    --Eric
     
    Alex_Bermann likes this.
  3. Alex_Bermann

    Alex_Bermann

    Joined:
    Feb 5, 2015
    Posts:
    6
    Sorry about the code tags (newbie alert!), and thanks you for your kind answer, Eric. My mistake, I thought OnTriggerEnter was a custom function name.

    Now, I have several gameObjects (with rigidBody attached) falling and bouncing into a plane. When they hit that plane, I want something to happen, but nothing goes on:

    Code (JavaScript):
    1. var particleDer : ParticleSystem;
    2.  
    3. function Start ()
    4. {
    5.  
    6. }
    7.  
    8. function Update ()
    9. {
    10.  
    11. }
    12.  
    13. function OnTriggerEnter(col:Collider)
    14. {
    15.     if (col.tag == "Ring")
    16.     {
    17.     print("Go on");
    18.     //particleDer.Play();
    19.     }
    20. }
    I´m sorry, I know this must be very basic stuff, but I can´t figure it out... Thanks.
     
  4. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,398
    You'd want OnCollisionEnter instead. BTW, it's better to use CompareTag instead of using string comparisons.

    --Eric
     
    Alex_Bermann likes this.
  5. Deleted User

    Deleted User

    Guest

    Alex_Bermann likes this.
  6. Alex_Bermann

    Alex_Bermann

    Joined:
    Feb 5, 2015
    Posts:
    6
    Thank you very much, Eric and element wsc