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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Scripts not recognized in Inspector + Unity 5 import issues

Discussion in 'Editor & General Support' started by DA5h_ProjekT, Jul 28, 2015.

  1. DA5h_ProjekT

    DA5h_ProjekT

    Joined:
    Dec 19, 2014
    Posts:
    7
    Hey guys, decided to kill two birds with one stone here and post two problems I've been having. First an issue with either the Inspector or my scripts, the other arose after upgrading to Unity 5.

    1st issue came up while following space shooter tutorial, right after writing and applying the DestroyByTime script to the explosions. Ran perfectly until I applied the script to the explosions...game then quits instantly.
    All objects' script components had error alerts, something about a compile error. Removed script components then put them back, no luck...option to add script was gone: only "add new script" was there.

    2nd problem happened just after I upgraded to Unity 5.1.2f1 last night. Went to import my project, after I opened it all the files are still there, but the scene is completely empty:

    Notice the red error message at the bottom. What is that about?

    And here's the scene view:


    Please help me ASAP with both issues. I really want to know what is going on...I worked so hard and am almost done with the tutorial. I don't want all my progress to be wiped!
     
    Last edited: Jul 28, 2015
  2. superpig

    superpig

    Drink more water! Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    4,614
    It looks like your DestroyByTime script has an error on line 13. If there are any errors in any of your scripts, it prevents them from being compiled, which is why none of them show up in the Add Component menu. Fix the compile error and they should come back.

    As far as the scene being empty goes: it looks like you just haven't opened the scene file (it still says 'Untitled' in the menu bar).
     
  3. DA5h_ProjekT

    DA5h_ProjekT

    Joined:
    Dec 19, 2014
    Posts:
    7
    Edit:
    Just found the problem... 'gameObject' instead of 'GameObject'. Derp. Trying to find errors is seriously like a game of Where's Waldo sometimes.

    But now I've got another problem. Apparently some of the features I've used here are no longer supported in Unity 5, so while the game would have worked perfectly now if I were still using Unity 4, it gives me the following error:
    which I fixed right away by re-assigning the Asteroid object to GameController's hazard variable slot.

    The other error prevents my ship from colliding with the asteroids, but for some reason doesn't prevent my laser bolts from being able to destroy the asteroids.
    I presume I am still able to destroy asteroids since my Asteroid object uses a capsule collider instead of a RigidBody collider.

    Original Message:
    I looked at line 13 and don't see much of any problem. I swear I followed the tutorial perfectly, my only difference is my neater coding style (I am a neat freak with my code, always been) and extensive commenting to help myself remember key points for future projects and so I don't have to go back and rewatch tutorials I've already seen. I guess I'll post my code here to see if you can find anything wrong with it:

    Code (CSharp):
    1. /* Space Shooter tutorial game
    2. * Destroy by time script
    3. *
    4. * Following Unity3D official tutorials
    5. * Created: 07/19/2015 */
    6.  
    7. using UnityEngine;
    8. using System.Collections;
    9.  
    10. public class DestroyByTime : MonoBehaviour
    11. {
    12.     public float lifetime; // How long a GameObject using this script stays onscreen before being destroyed (set within Unity)
    13.     void Start() {Destroy (GameObject, lifetime);}     /* Very simple code here, though it's worth noting that Destroy() can take more than one parameter
    14.                                                      *
    15.                                                       * The second parameter it takes is optional and delays the GameObject's destruction by a
    16.                                                       * # of seconds In this case we delay the destruction of any object using this script by
    17.                                                       * 'lifetime' # of seconds, again defined within Unity.
    18.                                                      *
    19.                                                      * If there is no time parameter then Destroy() simply destroys the object at the end of the frame or
    20.                                                       * Update loop like it always does regardless. Destruction is always done *before* rendering. */
    21. }
    And here's the example code (for comparison):
    Code (CSharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4.  
    5. public class DestroyByTime : MonoBehaviour
    6. {
    7.      public float lifetime;
    8.  
    9.      void Start ()
    10.      {
    11.           Destroy (gameObject, lifetime);
    12.      }
    13. }
    I am out of ideas...

    Huh, interesting. I didn't know that. So once I fix this one error in this one script, the option to add an existing script component to my objects will come back and I can proceed and finish the tutorial? I hope so..
    Thanks, that problem solved at least :cool:
     
    Last edited: Jul 28, 2015