- Home /
Question by
sacajawhoohoo · Mar 20, 2014 at 05:49 AM ·
errorelseelse if
"Else" not working
var bobbingSpeed = 0.2;
var bobbingAmount = 0.01;
var midpoint = 0.4;
function Update () {
waveslice = 0.0;
horizontal = Input.GetAxis("Horizontal");
vertical = Input.GetAxis("Vertical");
if (Mathf.Abs(horizontal) == 0 && Mathf.Abs(vertical) == 0) {
timer = 0.0;
}
else {
waveslice = Mathf.Sin(timer);
timer = timer + bobbingSpeed;
if (timer > Mathf.PI * 2) {
timer = timer - (Mathf.PI * 2);
}
}
if (waveslice != 0) {
translateChange = waveslice * bobbingAmount;
totalAxes = Mathf.Abs(horizontal) + Mathf.Abs(vertical);
totalAxes = Mathf.Clamp (totalAxes, 0.0, 1.0);
translateChange = totalAxes * translateChange;
transform.localPosition.y = midpoint + translateChange;
}
else {
transform.localPosition.y = midpoint;
}
if (Input.GetKeyDown("left shift") || Input.GetKeyDown("right shift"));
{
bobbingSpeed = 0.8;
}
else {
bobbingSpeed = 0.2;
}
}
I am getting the errors: BCE0044: expecting }, found 'else'. and BCE0044: expecting EOF, found '}'. What did I do? The brackets look fine to me.
Comment
Best Answer
Answer by Sildaekar · Mar 20, 2014 at 05:54 AM
That's because you have a semicolon on this line:
if (Input.GetKeyDown("left shift") || Input.GetKeyDown("right shift"));
Remove that semicolon and it should work. Also, for future reference it's best to let us know the line number you are having issues with so we can identify it quicker.
Answer by Destran · Mar 20, 2014 at 05:55 AM
" if (Input.GetKeyDown("left shift") || Input.GetKeyDown("right shift"));" you have a ";" at the end of your if
var bobbingSpeed = 0.2;
var bobbingAmount = 0.01;
var midpoint = 0.4;
function Update ()
{
waveslice = 0.0;
horizontal = Input.GetAxis("Horizontal");
vertical = Input.GetAxis("Vertical");
if (Mathf.Abs(horizontal) == 0 && Mathf.Abs(vertical) == 0)
{
timer = 0.0;
}
else
{
waveslice = Mathf.Sin(timer);
timer = timer + bobbingSpeed;
if (timer > Mathf.PI * 2)
{
timer = timer - (Mathf.PI * 2);
}
}
if (waveslice != 0)
{
translateChange = waveslice * bobbingAmount;
totalAxes = Mathf.Abs(horizontal) + Mathf.Abs(vertical);
totalAxes = Mathf.Clamp (totalAxes, 0.0, 1.0);
translateChange = totalAxes * translateChange;
transform.localPosition.y = midpoint + translateChange;
}
else
{
transform.localPosition.y = midpoint;
}
if (Input.GetKeyDown("left shift") || Input.GetKeyDown("right shift"))
{
bobbingSpeed = 0.8;
}
else
{
bobbingSpeed = 0.2;
}
}
This should work