资产/脚本/播放器.cs(40,36):错误 CS1519:类、结构或接口成员声明中出现意外的符号"("



在Unity中使用脚本时遇到一些问题。主要问题是我试图让我的玩家在我的播放器脚本中行走和闲置。错误是:解析错误 和意想不到的符号

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));
}
}

看起来您在animator.SetInteger("Animstate", 1);之前关闭了if (Input.GetKey ("right"))块,然后您有了else,但在这一点上,如果处于活动状态,则没有。

最新更新