2015-04-13 55 views
-1

在Unity中有一些麻煩,主要問題是我試圖我的球員的步行路程,在我的播放器腳本IDEL的錯誤是: 解析錯誤 和意外符號Assets/scripts/Player.cs(40,36):錯誤CS1519:類,結構或接口成員聲明中的意外符號'('

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

} 
} 
+0

您的大括號'{'需要匹配1對1。縮進將爲你帶來很大的幫助。 – Dan

回答

0

看起來你關閉animator.SetInteger("Animstate", 1);之前if (Input.GetKey ("right"))塊,然後你有你的else,但在這一點上,

相關問題