Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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?

share|improve this question
    
Error is ""No appropriate version of "UnityEngine.AnimationPlay" for the argument list". –  Paul Ferris Jun 12 '13 at 5:56
    
Could you show where the namespace code is referring to? –  Sidar Jun 12 '13 at 8:15
    
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. –  Byte56 Jun 12 '13 at 14:06
    
@Byte66 That is the exact error, I'll search it anyway though. –  Paul Ferris Jun 14 '13 at 1:00
    
@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. –  Paul Ferris Jun 14 '13 at 1:00

2 Answers 2

up vote 0 down vote accepted

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.

share|improve this answer
    
In fact, Unity does support scripts in namespaces since version 4.0, it just isn't reflected in the documentation for some reason. –  Alexander Konstantinov Jun 12 '13 at 10:26
    
That's weird =/ well i removed it in my answer. –  Sidar Jun 12 '13 at 11:53
    
Thanks :). My scripting experience is limited to websites, so games give me a lot to get used to. –  Paul Ferris Jun 14 '13 at 1:02

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.

share|improve this answer
    
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. –  Paul Ferris Jun 12 '13 at 6:17

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.