x


Compliler Error... Unexpected Char '''

In order to customize the effect of more then one button being held down at the same time, I have written a function called CheckButtons() that checks each frame to see which buttons are being held down, and then alters a variable named buttonsDown (string) which then can be accessed by other aspects of the script instead of the traditional Input.GetButton.... Here is the function:

function CheckButtons()
    {
        if(Input.GetButton("W"))
        {
            buttonsDown = buttonsDown + "w";
        }
        if(Input.GetButton("A"))
        {
            buttonsDown = buttonsDown + "a";
        }
        if(Input.GetButton("S"))
        {
            buttonsDown = buttonsDown + "s";
        }
        if(Input.GetButton("D"))
        {
            buttonsDown = buttonsDown + "d";
        }

    }

It is then accessed by the movement part of the script:

 if(buttonsDown = 'w')
{
    transform.position += transform.forward * moveSpeed * Time.deltaTime;
}

(Just one of many reactions to buttonsDown's current value.)

However, the pesky debugging console tells me that there is an unexpected character ''' in this line: if(buttonsDown = 'w'. I cannot seem to tell what error I made! I'm not that good with unity... so please be gentle if it's a really obvious mistake. Thanks!

more ▼

asked Dec 20 '10 at 05:21 PM

Jon 1 gravatar image

Jon 1
19 4 5 10

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

Not sure if its causing your error, but "buttonsDown = 'w'" (note the single equals sign) is an assignment operation and not equivalency. For equivalency you want to have "if(buttonsDowns == 'w')" using the double equals sign.

more ▼

answered Dec 20 '10 at 06:19 PM

davedev gravatar image

davedev
594 37 41 49

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

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

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1364
x952
x819
x418

asked: Dec 20 '10 at 05:21 PM

Seen: 994 times

Last Updated: Dec 20 '10 at 05:21 PM