Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Self destruction

Discussion in 'Scripting' started by R0b_, Sep 22, 2018.

  1. R0b_

    R0b_

    Joined:
    Jul 11, 2018
    Posts:
    25
    It doesn't work and I don't know why

    Code (csharp):
    1.  
    2.             if (BulletRigidbody.velocity.x < 0.2f && BulletRigidbody.velocity.x > -0.2f &&
    3.             BulletRigidbody.velocity.y < 0.2f && BulletRigidbody.velocity.y > -0.2f)
    4.             {
    5.                 Debug.Log("2");
    6.                 Destroy(Me);
    7.             }
    8.  
    When I run it I get this error:

    ArgumentOutOfRangeException: Argument is out of range.
    Parameter name: index
    System.Collections.Generic.List`1[UnityEngine.GameObject].get_Item (Int32 index) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Collections.Generic/List.cs:633)
    Movement.FixedUpdate () (at Assets/script/Playerbehaviour/Movement.cs:150)
     
  2. R0b_

    R0b_

    Joined:
    Jul 11, 2018
    Posts:
    25
    Nevermind is solved it.
     
  3. mjzx

    mjzx

    Joined:
    Aug 18, 2013
    Posts:
    114
    Are you sure that error corresponds to the code you posted? Go to line 150 in your Movement.cs script and check the line, as it seems to be an array or list-related error.