Hi guys,
this is my code:
void Update ()
{
ControllPlayer();
}
public void ControllPlayer()
{
if(controlsActive)
{
// movement
float moveHorizontal = Input.GetAxisRaw (moveHorizontal_plug);
float moveVertical = Input.GetAxisRaw (moveVertical_plug);
Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
transform.Translate(movement.normalized * movementSpeed * Time.deltaTime, Space.World);
if(moveHorizontal != 0 || moveVertical != 0)
{
transform.rotation = Quaternion.LookRotation(movement);
}
// animations
if (movement != Vector3.zero)
{ animation.CrossFade(run_anim); }
else
{ animation.CrossFade(idle_anim); }
if (Input.GetButtonDown(fireBtn_1_plug)) { animation.Blend(castSpellDirect_anim); }
else if (Input.GetButtonDown(fireBtn_2_plug)) { animation.Blend(castSpellAoE_anim); }
else if (Input.GetButtonDown(fireBtn_3_plug)) { /* animation.Blend(castSpellAoE_anim); */ }
else if (Input.GetButtonDown(fireBtn_4_plug)) { /* animation.Blend(castSpellAoE_anim); */ }
}
}
I know this will sound weird, but I have a bad feeling when I look at my newest creation. It works just fine and all, but still I think something is wrong with how I coded this out. Can anybody suggest how to improve this script? For example how to nest the if-else statements better?