Search Unity

Okay, this is weird

Discussion in 'Editor & General Support' started by FancyPants, Jul 7, 2005.

  1. FancyPants

    FancyPants

    Joined:
    Jun 30, 2005
    Posts:
    38
    I don't know if this should be a bug report or not, but I thought I would ask about it here.

    I wrote a script, put it into my scripts directory in my project asset directory, tried to attach it to an object, and it says that it can't add the script because it can't be found. And yet, when I click on the script to edit it, it comes up just fine, and saves my changes, etc. So I know that it can access it, and I know that the system knows about it because I am adding the script by clicking on Component->Scripts and mine is in there...

    Any thoughts?

    Thanks,
    --Thomas
     
  2. freyr

    freyr

    Joined:
    Apr 7, 2005
    Posts:
    1,148
    Do you get errors when saving the script after double-clicking and editing it from Unity?

    The errors show up in the status line at the bottom of the window, but you can also open a error console by selecting it from the Windows menu

    .... and what kind of script is it? C#, JavaScript, etc....?
     
  3. FancyPants

    FancyPants

    Joined:
    Jun 30, 2005
    Posts:
    38
    It's a C# script, and there are no errors on compilation.
     
  4. freyr

    freyr

    Joined:
    Apr 7, 2005
    Posts:
    1,148
    Can you post the script file to this thread, so I can take a look?
     
  5. FancyPants

    FancyPants

    Joined:
    Jun 30, 2005
    Posts:
    38
    Sure thing.
    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4.  
    5. public class TrackingMissle : MonoBehaviour {
    6.  
    7.     public Transform target;
    8.     public float rotationDamping = 1;
    9.     public Vector3   targetLookatOffset = new Vector3 (0, 0, 0);
    10.  
    11.     //All this does it makes it look at it. The actual movement is created using a ConstantForce on the missle object.
    12.     // Update is called once per frame
    13.     void LateUpdate () {
    14.         if(target) {
    15.             Vector3 globalLookPos = target.TransformPoint (new Vector3 (targetLookatOffset.x, 0, targetLookatOffset.z));
    16.             globalLookPos.y += targetLookatOffset.y;
    17.  
    18.             Quaternion lookRoation = Quaternion.LookRotation (globalLookPos - transform.position, Vector3.up);
    19.             transform.rotation = Quaternion.Slerp (transform.rotation, lookRoation, rotationDamping * Time.deltaTime);
    20.         }//end if
    21.     }//end function
    22. }//end class
    23.  
    [/code]
     
  6. freyr

    freyr

    Joined:
    Apr 7, 2005
    Posts:
    1,148
    I just pasted the code into a newly created file and it worked fine.

    Have you checked that the file name is the same as the name of the class? (It looks like you have made a small typo in the class declaration, the class is called TrackingMissle and not TrackingMissile.)
     
  7. FancyPants

    FancyPants

    Joined:
    Jun 30, 2005
    Posts:
    38
    I fixed the typo, and no go. I pasted the code into a new file all-together, and it still does not work.. This is all very strange, indeed...
     
  8. freyr

    freyr

    Joined:
    Apr 7, 2005
    Posts:
    1,148
    Is it possible for you to zip up the project directory and place it somewhere I can download it?

    What is the exact error message you get when you try to attach the behavior to an object?

    ... and you pasted it into a new file, you say... What did you call that file? Remember that file name and class name has to match exactly.
     
  9. FancyPants

    FancyPants

    Joined:
    Jun 30, 2005
    Posts:
    38
    The file name was called "TrackingMissile.cs".
    The exact error message is "Can't add script, because it couldn't be found".
    I can't zip up the project directory at the moment, because it is just FILLED with way too much crap.. I'll see what I can do, though.

    Thank you for your help, btw!
     
  10. freyr

    freyr

    Joined:
    Apr 7, 2005
    Posts:
    1,148
    Ah!.... now I see...

    I was not adding the script using the Component menu, but by dragging it from the the project view onto the object. It seems like we have an actual bug here.

    You can add the script by dragging it onto the object in the scene or in the hierarchy view, which should work fine.
     
  11. FancyPants

    FancyPants

    Joined:
    Jun 30, 2005
    Posts:
    38
    well, that at least explains it. When I drag the script on to an object in the scene, it works fine. The down-side is that I want to add the script to a pre-fab (a missile object that is spawned when something is shot).. It won't let me drag the script from the project view onto another object in the project view! Grrrr....

    Anyway, I'll file the bug report, and hopefully this will all get worked out..
     
  12. freyr

    freyr

    Joined:
    Apr 7, 2005
    Posts:
    1,148
    It's already filed.

    I noticed that adding scripts from the component menu only fails if the script name contains an uppercase character inside the name, so renaming the script (and class) to Trackingmissile should fix your problem.
     
  13. FancyPants

    FancyPants

    Joined:
    Jun 30, 2005
    Posts:
    38
    That seems to have done the trick! Thanks!

    I bet I can guess where the error is! ;)