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

Still Try to access ... Script Error .

Discussion in 'Editor & General Support' started by JeevanjotSingh, Nov 18, 2014.

  1. JeevanjotSingh

    JeevanjotSingh

    Joined:
    Apr 30, 2014
    Posts:
    251
    Last edited: Nov 19, 2014
  2. Dustin-Horne

    Dustin-Horne

    Joined:
    Apr 4, 2013
    Posts:
    4,568
    The error tells you exactly what's wrong and where. Look at line 17 in your CameraController.cs. It's trying to do something with one of the game objects that you've destroyed.
     
    JeevanjotSingh likes this.
  3. JeevanjotSingh

    JeevanjotSingh

    Joined:
    Apr 30, 2014
    Posts:
    251
    Thanks for the fastest reply .
    so how can i correct it , can you please suggest me (i am a newbie)
     
  4. JeevanjotSingh

    JeevanjotSingh

    Joined:
    Apr 30, 2014
    Posts:
    251
    And one more thing that how can i print my health using debug.log
     
  5. Dustin-Horne

    Dustin-Horne

    Joined:
    Apr 4, 2013
    Posts:
    4,568
    go to line 17. Add this around it and replace "someObject" with whatever object you're trying to access Again, look at the error:

    Code (csharp):
    1.  
    2. if(someObject != null)
    3. {
    4.  
    5. }
    6.  
     
    JeevanjotSingh likes this.
  6. JeevanjotSingh

    JeevanjotSingh

    Joined:
    Apr 30, 2014
    Posts:
    251
    Can you please tell me because it's too much hard for me (i am a newbie in c#)
    to understand where i have to write and what to write instead of "some object"
    Is it add with tag like gameobject.tag=="Player" != null or something like that .
    Please reply me and help me fast .
     
  7. Dustin-Horne

    Dustin-Horne

    Joined:
    Apr 4, 2013
    Posts:
    4,568
    I highly recommend you start with the beginner tutorials and documentation, otherwise we'll be doing this all day:

    http://www.unity3d.com/learn
     
    Ricks and JeevanjotSingh like this.
  8. JeevanjotSingh

    JeevanjotSingh

    Joined:
    Apr 30, 2014
    Posts:
    251
    That's right .
    thanks .
     
  9. JeevanjotSingh

    JeevanjotSingh

    Joined:
    Apr 30, 2014
    Posts:
    251
    So is there the memory leaks .
    So here i can i stop this , thanks
     
  10. JeevanjotSingh

    JeevanjotSingh

    Joined:
    Apr 30, 2014
    Posts:
    251
    If i add this one in my CameraController.cs in LateUpdate() Function
    1. if (gameObject != null)
    2. {
    3. // Do something
    4. Destroy(gameObject);
    5. }


    then Console said "There are no audio listeners in the scene. Please ensure there is always one audio listener in the scene"
    and my camera didn't show anything
    and if i add in enemy nothing happens it will continuously saying about my first error if the player destroy .
    Please help me .
     
  11. Ricks

    Ricks

    Joined:
    Jun 17, 2010
    Posts:
    650
    The console says you need at least one AudioListener in the scene. This is a component which you can attach to any object. Generally the main camera has automatically attached one, so if you destroy the camera, it's gone, thereby causing the error.
     
  12. JeevanjotSingh

    JeevanjotSingh

    Joined:
    Apr 30, 2014
    Posts:
    251
    yes that's what actually happens can you please tell me how can i insert this to get rid from this two "Missing Reference Errors"
     
  13. Ricks

    Ricks

    Joined:
    Jun 17, 2010
    Posts:
    650
    The problem in your other script is, that on the collision with the enemy you destroy the player (including its camera), instead of destroying the enemy. This part causes all errors:

    When you use "gameObject" the GameObject where the script is attached to is referred.
    So in your case you actually destroyed the Player himself. Instead you want to delete the colliding GameObject which is: Destroy(col.gameObject);
     
    Last edited: Nov 19, 2014
  14. JeevanjotSingh

    JeevanjotSingh

    Joined:
    Apr 30, 2014
    Posts:
    251
    When i destroy the collision of the "Player" Game Object same thing will happen (Two errors )
    I just assign health for enemy but here in the enemy script i destroy the collision of player but again those errors .