I did an animation of a widget within a model in Maya, brought it into Unity(2.5_windows), and would like the widget animation to play when I hit the “a” key (“Left”).
But, I’m NOT a programmer, so I’m dealing with learning UnityScript… sigh…
My non working code is
function Update() {
if (Input.GetButton ("Left")) {
transform.root.animation.Play("openLeft");
}
}
which, of course doesn’t work (or I wouldn’t be writing this). When I tried putting it onto the model I got an error:
(Can’t add script behaviour OpenAction. The scripts file name does not match the name of the class defined in the script!)
I would like to know what this means and I’d like to know how to code something that would do the job.
You should definitely not do that kind of code in OnGUI. Update is correct.
When using Javascript, the script can be called anything you want (although stay away from duplicating Unity classes, like don’t name scripts GUI, etc.). I’d try reimporting the script; this seems to be a bug that occasionally happens to some people.
There are cases where you don’t need to have a script and class names matching in C#. Library stuff that doesn’t inherit from MonoBehaviour, for example. It is always stated so absolute on the forum, that I had to pause to ask Joe what I was supposed to name a file for this:
public interface Graph<T>{ ... }
The answer, which makes total sense in hindsight, is “whatever”.
Back to the original post… are you sure it is this file creating the problem and that the problem is tied to the code you posted? I only ask because the name mentioned in the error isn’t tied to the name you just said. Or am I missing something? (I’m sleepy… cold medication has me a bit groggy today)
Correct, of course, but I did not want to formulate it to complex: If a name mismatch between file and class would have been the reason for the problem in this case, it would have been no direct help to know, that it would have been ok for other classes.
Honestly, I’m not too sure of anything at the moment. :shock:
Let me see… you mean the name widget isn’t the same as “openLeft”? openLeft is the animation frame name (11 to 15) I set up on importing the model from Maya.
What error messages beyond “Can’t add script. Cant’s add script behaviour FlipperAction. You need to fix all compile errors in all scripts first!” are you getting?
Took out another script and changed Function Update() to function Update().
No more errors. Granted, the code doesn’t do what I want and I’m getting a “UnityException:Input Button Left is not setup” in the console, but at least now…