-2
\$\begingroup\$

I have the following code set out for a simple animation in Unity:

#pragma strict
function Start () {

}

function Update () {
    if (Input.GetButtonDown("KeyCode.W")){
        animation.Play("dogWalk", WrapMode.Loop);
    }
};

Unfortunately, I have no idea what to do with namespaces (since they occasionally pop up as warnings but don't seem to have any purpose), and line 12 (animation.Play("dogWalk", WrapMode.Loop);) keeps generating an error regarding UnityEngine. What does it mean, and how do I fix it?

TL;DR:

  • What do namespaces do?

  • What does the error mean and how do I get rid of it?

\$\endgroup\$
6
  • \$\begingroup\$ Error is ""No appropriate version of "UnityEngine.AnimationPlay" for the argument list". \$\endgroup\$ Commented Jun 12, 2013 at 5:56
  • \$\begingroup\$ Could you show where the namespace code is referring to? \$\endgroup\$ Commented Jun 12, 2013 at 8:15
  • \$\begingroup\$ If you ever have a problem with an error code, try searching the error message with Google. If you can't find anything, when you ask the question, you should post the exact error message text. \$\endgroup\$ Commented Jun 12, 2013 at 14:06
  • \$\begingroup\$ @Byte66 That is the exact error, I'll search it anyway though. \$\endgroup\$ Commented Jun 14, 2013 at 1:00
  • \$\begingroup\$ @Sidar I'm not sure. All I know is that UnityEngine is one and that the code was complaining that I didn't have any. \$\endgroup\$ Commented Jun 14, 2013 at 1:00

2 Answers 2

0
\$\begingroup\$

Namespaces are like "virtual folders" where you put your classes in. Just in code. Like how Packages work in Java or AS3. Eventhough in those two languages they are explicitly structured in actual folders too. It prevents Class names to conflict with each other and it allows for vendors to be denoted.

For example:

com.paulsoft.game.MyObject;

Like @Tetrad said, you're passing an argument to the function that is invalid.

\$\endgroup\$
3
  • \$\begingroup\$ In fact, Unity does support scripts in namespaces since version 4.0, it just isn't reflected in the documentation for some reason. \$\endgroup\$ Commented Jun 12, 2013 at 10:26
  • \$\begingroup\$ That's weird =/ well i removed it in my answer. \$\endgroup\$ Commented Jun 12, 2013 at 11:53
  • \$\begingroup\$ Thanks :). My scripting experience is limited to websites, so games give me a lot to get used to. \$\endgroup\$ Commented Jun 14, 2013 at 1:02
1
\$\begingroup\$

You're calling animation.Play with the wrong argument types.

http://docs.unity3d.com/Documentation/ScriptReference/Animation.Play.html

The second parameter is a PlayMode, not a WrapMode.

\$\endgroup\$
1
  • \$\begingroup\$ You may use PlayMode for stopping animations, but the scripting reference says you use WrapMode to define how they run (as a loop, once, etc). But I'm not sure how well I'm using it, since it isn't working and all. \$\endgroup\$ Commented Jun 12, 2013 at 6:17

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.