user3533784
user3533784

Reputation: 53

Unity - Unexpected Symbol ";" in class, struct or interface member declaration

having a slight problem. I am reworking a project of mine using SpriteFactory, and have used a youtube following the exact same code as his but running into the following error:

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();
}
}
}

Error It results in is Unexpected Symbol ";" in class, struct or interface member declaration which i know is referring to:

private SpriteFactory.Sprite;

but I am not even sure why? Suggestions

Upvotes: 1

Views: 3625

Answers (1)

trebor
trebor

Reputation: 734

Here you go :)

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();
     }
  }
}

Upvotes: 2

Related Questions