-2

I' beginner with C#. I was coding my first game and got error:Too many characters in character literal. How to fix it?

if (Input.GetAxisRaw('Horizontal') < 0.5f)                
{         
    transform.Translate(new Vector3(Input.GetAxisRaw('Horizontal' * moveSpeed * Time.deltaTime)));
}
Marc
  • 3,905
  • 4
  • 21
  • 37
Mats Lepp
  • 7
  • 1
  • 1

2 Answers2

2

You should use double quotes instead:

if (Input.GetAxisRaw("Horizontal") < 0.5f);
{
    transform.Translate(new Vector3(Input.GetAxisRaw("Horizontal") * moveSpeed * Time.deltaTime));
}
S.Spieker
  • 7,005
  • 8
  • 44
  • 50
2

I see 2 things wrong.

First, Input.GetAxisRaw takes string as a parameter and string literals with used double quotes "" not single quotes ''. Single quotes are used for char type. That's why you should it as;

Input.GetAxisRaw("Horizontal")

Second, that method returns float and if you do some calculations about that, the right syntax should be

Input.GetAxisRaw("Horizontal") * moveSpeed * Time.deltaTime

not

Input.GetAxisRaw('Horizontal' * moveSpeed * Time.deltaTime))
Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
  • 1
    Well, at least this is a plausible explanation of that _string mutiplication operator_ – Steve Feb 28 '16 at 16:35
  • @Steve _string mutiplication operator_ Nice one :) – Soner Gönül Feb 28 '16 at 16:38
  • 1
    Oh, well I thought I was being original, but there is also a question about that: [Can I “multiply” a string (in C#)?](http://stackoverflow.com/questions/532892/can-i-multiply-a-string-in-c) – Steve Feb 28 '16 at 16:42