团结 - 意想不到的符号“;”在类,结构或接口成员声明中

时间:2014-04-14 21:55:48

标签: c# unity3d

有轻微的问题。我正在使用SpriteFactory重新编写一个我的项目,并使用了与他完全相同的代码的youtube,但遇到了以下错误:

using UnityEngine;
using System.Collections;
using SpriteFactory;
public class Running : MonoBehaviour {

private SpriteFactory.Sprite;

// Use this for initialization
void Start () {
    sprite = GetComponent<Sprite> ();
    }

// Update is called once per frame
void Update () {
if(Input.GetKey(KeyCode.RightArrow)) {
        Sprite.Play("Run");
        Vector3 pos = transform.position;
        pos.x += Time.deltaTime * 2;
        transform.position = pos;
        }
    else{
        sprite.Stop();
}
}
}

错误导致意外符号“;”在类,结构或接口成员声明中,我知道是指:

private SpriteFactory.Sprite;

但我不确定为什么?建议

1 个答案:

答案 0 :(得分:2)

你走了:))

using UnityEngine;
using System.Collections;
// below solved conflict of class names
// we won't "using" whole SpriteFactory namespace because
// both UnityEngine and SpriteFactory have got same class "Sprite"
// so we pull out only needed class
using FactorySprite = SpriteFactory.Sprite;
public class Running : MonoBehaviour {

   // you forgot to set name of variable representing your sprite
   private FactorySprite sprite;

   // Use this for initialization
   void Start () {
      sprite = GetComponent<FactorySprite> (); // Edited
   }

  // Update is called once per frame
  void Update () {
     if(Input.GetKey(KeyCode.RightArrow)) {
        sprite.Play("Run"); // heh, remember C# is case sensitive :)
        Vector3 pos = transform.position;
        pos.x += Time.deltaTime * 2;
        transform.position = pos;
     }
     else{
        sprite.Stop();
     }
  }
}