意外符号 CS1525 变量名称
本文关键字:变量名 CS1525 符号 意外 | 更新日期: 2023-09-27 17:56:52
我已经修改了一些代码以满足我的需求。虽然变量"dest"应该是一个局部变量(我认为),那么为什么在为dest分配值的行上会出现一个错误,并带有"意外的符号'dest'"错误,我将如何解决它?(这是链接:http://noobtuts.com/unity/2d-pacman-game)
using UnityEngine;
using System.Collections;
public class SepticSamMove : MonoBehaviour
{
public float speed = 0.4f;
Vector2 dest = Vector2.zero;
// Use this for initialization
void Start ()
{
dest = transform.position;
}
// Update is called once per frame
void FixedUpdate ()
{
//move closer to Destination
Vector2 p =Vector2.MoveTowards(transform.position,dest,speed);
GetComponent<Rigidbody2D> ().MovePosition (p);
//check input for movement
if ((Vector2)transform.position == dest)
{
//up
if(Input.GetKey(KeyCode.W) && valid(Vector2.up)
dest = (Vector2)transform.position+Vector2.up;
if(Input.GetKey(KeyCode.S) && vaild(-Vector2.up)
dest = (Vector2)transform.position - Vector2.up;
if(Input.GetKey(KeyCode.D) && valid(Vector2.right)
dest = (Vector2)transform.position+Vector2.right;
if(Input.GetKey(KeyCode.A) && valid(-Vector2.right)
dest =(Vector2)transform.position-Vector2.right;
}
// Animation Parameters
Vector2 dir = dest - (Vector2)transform.position;
GetComponent<Animator>().SetFloat("DirX", dir.x);
GetComponent<Animator>().SetFloat("DirY", dir.y);
}
bool vaild (Vector2 dir)
{
//cast Line from 'Next to Septic Sam' to SepticSam
Vector2 pos= transform.position;
RaycastHit2D hit = Physics2D.Linecast (pos + dir, pos);
return (hit.collider == GetComponent<Collider2D> ());
}
}
您缺少右括号:
if(Input.GetKey(KeyCode.W) && valid(Vector2.up)
dest = (Vector2)transform.position+Vector2.up;
应该是
if(Input.GetKey(KeyCode.W) && valid(Vector2.up)) //added ')'
dest = (Vector2)transform.position+Vector2.up;