Assets / scripts / Player.cs(40,36):错误CS1519:意外的符号`('在类,结构或接口成员声明中)

时间:2015-04-13 00:06:48

标签: c# unity3d monodevelop

在Unity with Scripting中遇到一些麻烦。主要问题是我试图让我的玩家在我的播放器脚本中走路和想法。错误是: 解析错误  和意外的符号

using UnityEngine;
using System.Collections;

public class Player : MonoBehaviour {

public float speed = 10f;
public Vector2 maxVelocity = new Vector2(3,5);
public bool standing;
public float jump = 15f;
public float airSpeedMultipler = .3f;
private Animator animator;

void start (){
    animator = GetComponent<Animator> ();
}
// Update is called once per frame
void Update () {
    var forceX = 0f;
    var forceY = 0f;

    var absVelX = Mathf.Abs (GetComponent<Rigidbody2D> ().velocity.x);
    var absVelY = Mathf.Abs (GetComponent<Rigidbody2D> ().velocity.y);

    if (absVelY < .2f) {
        standing = true;
    } else {
        standing = false;
    }

    if (Input.GetKey ("right")) {

        if (absVelX < maxVelocity.x)

            forceX = standing ? speed : (speed * airSpeedMultipler);

        transform.localScale = new Vector3 (1, 1, 1);
    }
    animator.SetInteger("Animstate", 1);
} else {
    animator.SetInteger("Animstate",0);
        }

    } else if (Input.GetKey ("left")) {

        if (absVelX < maxVelocity.x)
            forceX = standing ? -speed : (-speed * airSpeedMultipler);

        transform.localScale = new Vector3(-1, 1, 1);
    }

    if (Input.GetKey ("up")) {
        if (absVelY < maxVelocity.y)
            forceY = jump;
    }

    GetComponent<Rigidbody2D>().AddForce(new Vector2 (forceX, forceY));

}
}

1 个答案:

答案 0 :(得分:0)

您似乎在if (Input.GetKey ("right"))之前关闭了animator.SetInteger("Animstate", 1);的阻止,然后您拥有了else,但此时,如果有效则不会。