• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by TheIronHobo · Jul 23, 2013 at 07:39 PM · identifierexpected

error CS1041: Identifier expected. Well what now?

Hello, I am fairly new to the c# language and and programming in general and I am having trouble with a piece of code. This one to be precise.

 using UnityEngine;
 using System.Collections;
 
 public class Walker : MonoBehaviour {
 
     //Storing the reference to RagePixelSprite -component
     private IRagePixel ragePixel;
      public TTA_Coord coord;
     //enum for character state
     public enum WalkingState {Standing=0, WalkRight, WalkLeft};
     public WalkingState state = WalkingState.Standing;
 
     //walking speed (pixels per second)
     public float walkingSpeed = 10f;
 
     void Start () {
         ragePixel = GetComponent<RagePixelSprite>();
     }
 
     void Update () {
 
         //Check the keyboard state and set the character state accordingly
         Walker();
 
         Vector3 moveDirection = new Vector3();
         
         switch (state)
         {
             case(WalkingState.Standing):
                 //Reset the horizontal flip for clarity
                 ragePixel.SetHorizontalFlip(false);
                 ragePixel.PlayNamedAnimation("STAY", false);
                 break;
 
             case (WalkingState.WalkLeft):
                 //Flip horizontally. Our animation is drawn to walk right.
                 ragePixel.SetHorizontalFlip(true);
                 //PlayAnimation with forceRestart=false. If the WALK animation is already running, doesn't do anything. Otherwise restarts.
                 ragePixel.PlayNamedAnimation("WALK", false);
                 //Move direction. X grows right so left is -1.
                 moveDirection = new Vector3(-1f, 0f, 0f);
                 break;
 
             case (WalkingState.WalkRight):
                 //Not flipping horizontally. Our animation is drawn to walk right.
                 ragePixel.SetHorizontalFlip(false);
                 //PlayAnimation with forceRestart=false. If the WALK animation is already running, doesn't do anything. Otherwise restarts.
                 ragePixel.PlayNamedAnimation("WALK", false);
                 //Move direction. X grows right so left is +1.
                 moveDirection = new Vector3(1f, 0f, 0f);
                 break;
         }
 
         //Move the sprite into moveDirection at walkingSpeed pixels/sec
         transform.Translate(moveDirection * Time.deltaTime * walkingSpeed);
     }
     
     
     public Walker(int TTA_Coord coord)
     {
         
                 this.coord = new coord.x();
         
         
         if (Input.GetKey(KeyCode.LeftArrow))
         {
             state = WalkingState.WalkLeft;
         }
         else if (Input.GetKey(KeyCode.RightArrow))
         {
             state = WalkingState.WalkRight;
         }
         else
         {
             state = WalkingState.Standing;
         }
     }
 
     
     
 }



I cant seem to reference my other class "TTA_Coord" Properly. All I need from TTA_Coord is the integers x y and z that are being updated at run time to be output to my component script "Walker". But ALAS I cannot find a way to do so! Any help would be gladly appreciated. The error is specifically at line 59. Thanks bunches, TheIronHobo

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Seth-Bergman · Jul 23, 2013 at 07:40 PM 0
Share

which line is 57?

avatar image TheIronHobo · Jul 23, 2013 at 07:42 PM 0
Share

Oh! Apoligies, I meant line 59 the "public Walker(int TTA_Coord coord)". I'll edit that right now.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Seth-Bergman · Jul 23, 2013 at 07:57 PM

first, I don't think the method should be named "Walker", since it is also the name of the class..

okay, next, at the top you declare this variable:

 public TTA_Coord coord;

then, with your new method, you seem to be attempting to add this as an argument, which is wrong.. arguments are for data that is passed in when the method is called, as in, if you were calling it as :

 Walker(coord); //in order to pass in the data

in which case you would declare it as:

 public Walker(int myPassedCoord){  //for example

then you just refer to myPassedCoord like a normal var:

 int myX = myPassedCoord.x;

BUT, this is all unnecessary here, so just declare Walker thusly:

 public Walker(){

Now, as for your other class, TTA_Coord, that you wish to access, is it on the same object as this script? If so all you need to say is:

 coord = GetComponent<TTA_Coord>();

if not, you need to find the object first and store a reference:

 coord = GameObject.Find("NameOfObject").GetComponent<TTA_Coord>();


either way, you can then use "coord"

also, you should get rid of this line:

 this.coord = new coord.x();

can't really tell what you meant there, but it's not necessary

hope this helps

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image TheIronHobo · Jul 23, 2013 at 08:03 PM 0
Share

Thank you. This is very informative but I have one more question. What if TTA_Coord is not inside of a game object?

avatar image Seth-Bergman · Jul 23, 2013 at 08:20 PM 0
Share

where is it? or am I misunderstanding your intent.. I thought you wanted to pass data from another script.. you probably should just attach it to the same object as this script is attached to..

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

16 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

iOS Unique identifier deprecated? 1 Answer

identifier expected 1 Answer

So my problem is that after I finished coding for my Maze I had gotten a simple error called "UCE0001: ';' expected. Insert a semicolon at the end." This here is my script and the error is on both Lines (9,15) and (10,15). 1 Answer

Unexpected char:0xFEFF and Unknown PlayerStateController? 1 Answer

UNET - Why is my NetworkInstanceID equal on both clients when receiving ClientRpc? 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges