帮助,C#语法错误“预期; " [英] Help, C# syntax error "expected ; "

查看:149
本文介绍了帮助,C#语法错误“预期; "的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是使用C#的新手,我正在尝试为2D游戏制作一个基本的玩家控制器。尽管翻转功能(我创建的一个功能是在水平轴上将玩家精灵翻转到他正在移动的位置)在多个位置出现问题,但左右移动仍能正常工作。



当我找不到合理的原因时,显然预计会有两个分号,而且我不是在写一些正确的内容它给了我一个错误,无效的表达式术语=



我会加粗出现这些错误的评论。



I am new to using C#, and i'm trying to make a basic player controller for a 2d game. Left and right movements work properly with this although there is a problem with the "Flip" function (A function i've created to flip the player sprite on the horizontal axis to face where he is moving) at multiple places.

one one line there was apparently expected to be two semicolons when I can't find a reason for that being, and one one line I am not writing something right and it is giving me an error that "Invalid expression term "="

I will bold the comments in which these errors appear.

using UnityEngine;
using System.Collections;

public class TyroneController : MonoBehaviour {

	public float maxSpeed = 10f;
	bool facingRight = true;
	Rigidbody2D myRigidbody2D;



	void Start (){
		myRigidbody2D = this.GetComponent<Rigidbody2D>();



	}


	void FixedUpdate ()
	{
		float move = Input.GetAxis ("Horizontal"); //expected ;

		myRigidbody2D.velocity = new Vector2( move * maxSpeed, myRigidbody2D.velocity.y);

		if (move > 0 &&!facingRight)
			Flip ();
		else if (move < 0 && facingRight)
			Flip ();
	}

	void Flip ()
	{
		facingRight = !facingRight;
		Vector3 theScale = transform.localScale;
		theScale.x *= -1; //invalid expression term "="
		transform.localScale = theScale;
	}

}





我尝试过: < br $>


查看代码,查找正确的c#语法。



What I have tried:

Reviewing the code, and looking up proper c# syntax.

推荐答案

代码没有问题你确定这是你的确切代码吗?



如果这是在monodevelop中,那么我建议你重新启动Unity,因为代码没问题。



我能想到的唯一可能是你的脚本文件叫做TyroneController.cs。我记得团结对于必须匹配文件名的类名非常迂腐,但我认为它给出了一个特定的错误。
There is nothing wrong with the code are you sure that is the exact code you have?

If this is in monodevelop then I suggest you restart unity because that code is fine.

The only possibility I can think of is your script file isn't called TyroneController.cs . I remember unity is very pedantic about about the classname having to match the filename but I thought it gave a specific error to that effect.


这篇关于帮助,C#语法错误“预期; &QUOT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆