Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/279.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 花括号问题_C#_Unityscript - Fatal编程技术网

C# 花括号问题

C# 花括号问题,c#,unityscript,C#,Unityscript,我目前正在编写我的代码,但是我遇到了一个障碍,在//屏幕右侧,而不是卷曲的括号关闭了我的if语句,它关闭了整个代码。谁能告诉我为什么?此零件前的花括号工作正常。 下面是我的代码: public class ShipPlayerController : MonoBehaviour { //The reference to the bullet prefab. To be populated in the editor via the Inspector window. public Projec

我目前正在编写我的代码,但是我遇到了一个障碍,在//屏幕右侧,而不是卷曲的括号关闭了我的if语句,它关闭了整个代码。谁能告诉我为什么?此零件前的花括号工作正常。 下面是我的代码:

public class ShipPlayerController : MonoBehaviour {

//The reference to the bullet prefab. To be populated in the editor via the Inspector window.
public Projectile Bullet;

//Determines the screen bounds in relation to the player object. This camera object needs to e populated this attribute in the Inspector
public Camera CameraObject;

//Control how quickly we can fire (delay between shots)
public float FireRate = 0.5f;

//The amount of time since we last fired our weapon
private float FireTimer = 0.0f;

//Used to control how fast the ship moves
[Range(1f, 100f)]
[SerializeField]
public float MoveSpeed = 25.0f;

//Used to control how fast the ship moves when the t button is pressed
[Range(1f, 100f)]
[SerializeField]
public float ThrusterSpeed = 50.0f;

//Helper vector for updating the ship's position declared here since it is used every update/tick and we do not want to waste CPU power recreating it constantly.
private Vector3 movement = Vector3.zero;

public Rigidbody rb;

// Use this for initialization
void Start() {
    rb = GetComponent<Rigidbody>();
}

// Update is called once per frame
void Update() {

    UpdatePosition();
    UpdateFiring();
    FixedUpdate();

}

//Update the position of the ship based on the "Horizontal" and "Vertical" input
void UpdatePosition() {
    //Move the player laterally in the 'X' coordinate
    movement.x = Input.GetAxis("Horizontal") * Time.deltaTime * MoveSpeed;

    //Move the player laterally in the 'Y' coordinate
    movement.y = Input.GetAxis("Vertical") * Time.deltaTime * MoveSpeed;

    //Apply the movement vector to the game object's postion
    gameObject.transform.Translate(movement);

    //Transform the 3D world position to a screen pixel location
    Vector3 screenPosition = CameraObject.WorldToScreenPoint(
                                gameObject.transform.position);
}

    //Off screen to the RIGHT
    if (screenPosition.x > Screen.width) {

        //Clamp (reset) to the screen's right side
        screenPosition.x = 0; 

        //Transform clamped screen position to the world space and assign to player ship
        gameObject.transform.position = CameraObject.ScreenToWorldPoint(screenPosition); }

    //Off screen to the LEFT
    else if (screenPosition.x< 0) 

        //Clamp (reset) to the screen's left side
        screenPosition.x = Screen.width;

        //Transform clamped screen position to world space and assign player to ship
        gameObject.transform.position = CameraObject.ScreenToWorldPoint(screenPosition); 

    //Off screen to the TOP
    if (screenPosition.y > Screen.width) 
        //Clamp (reset) to the screen's top side
        screenPosition.y = 0;

        //Transform clamped screen position ti the world space and assign to the player ship
        gameObject.transform.position =
            CameraObject.ScreenToWorldPoint(screenPosition); }

    //Off screen to the BOTTOM
    else if (screenPosition.y< 0) {

        //Clamp (reset) to the screen's bottom side
        screenPosition.y = 0;

        //Transform clamped screen position to the world space and assign player to the ship
        gameObject.transform.position =
            CameraObject.ScreenToWorldPoint(screenPosition); 

    void FixedUpdate()
     if (Input.GetKey.(KeyCode.T)) {

     rb.AddForce(0, 0, ThrusterSpeed, ForceMode.Impulse); }


//Update the firing of the ship based on "Fire1" inout
void UpdateFiring() {

//Accumulate time each frame, when the fire key is pressed, we check if enough time has passed.
FireTimer += Time.deltaTime;

//Detect if the fire button has been pressed.
    if (Input.GetButton("Fire1")) { }

    //Has the fire timer exceeded the amount o time between the spawning of projectiles?
    if (FireTimer > FireRate) { }

        //Reset the timer so it will start counting from scratch for the next shot.
        FireTimer = 0;

//Call the function which handles the spawning of projectiles.
DoWeaponFire(); }

//Handles the spawning of the projectile
void DoWeaponFire() {

//Create a new instance of the bullet and place it at the location of the player, facing in the same direction.
Instantiate(Bullet, transform.position, transform.rotation); }
公共类ShipPlayerController:MonoBehavior{
//要通过Inspector窗口在编辑器中填充的对项目符号预置的引用。
公共射弹;
//确定与玩家对象相关的屏幕边界。此摄影机对象需要在检查器中填充此属性
公共摄像机;
//控制我们开火的速度(两次射击之间的延迟)
公共浮式消防车的火灾率=0.5f;
//我们上次开火的时间
专用浮式灭火器=0.0f;
//用来控制船的移动速度
[射程(1f、100f)]
[序列化字段]
公共浮子移动速度=25.0f;
//用于控制按下t按钮时船舶移动的速度
[射程(1f、100f)]
[序列化字段]
公共浮子推进器速度=50.0f;
//用于更新此处声明的船舶位置的辅助向量,因为它在每次更新/滴答声中都会被使用,我们不想浪费CPU资源不断地重新创建它。
私有向量3移动=向量3.0;
公共刚体;
//用于初始化
void Start(){
rb=GetComponent();
}
//每帧调用一次更新
无效更新(){
UpdatePosition();
UpdateFiring();
固定更新();
}
//根据“水平”和“垂直”输入更新船舶位置
void UpdatePosition(){
//在“X”坐标中横向移动玩家
movement.x=Input.GetAxis(“水平”)*Time.deltaTime*MoveSpeed;
//在“Y”坐标中横向移动玩家
movement.y=Input.GetAxis(“垂直”)*Time.deltaTime*MoveSpeed;
//将移动向量应用于游戏对象的位置
游戏对象。变换。平移(运动);
//将3D世界位置转换为屏幕像素位置
Vector3屏幕位置=CameraObject.WorldToScreenPoint(
游戏对象。变换。位置);
}
//屏幕右侧
如果(屏幕位置.x>屏幕宽度){
//夹紧(复位)到屏幕右侧
屏幕位置x=0;
//将固定屏幕位置转换为世界空间并指定给玩家飞船
gameObject.transform.position=CameraObject.ScreenToWorldPoint(screenPosition);}
//屏幕左侧
否则如果(屏幕位置x<0)
//夹紧(复位)屏幕左侧
screenPosition.x=Screen.width;
//将夹紧的屏幕位置转换为世界空间,并将玩家分配给飞船
gameObject.transform.position=CameraObject.ScreenToWorldPoint(screenPosition);
//从屏幕到顶部
if(屏幕位置y>屏幕宽度)
//夹紧(复位)至屏幕顶部
屏幕位置y=0;
//在世界空间中变换屏幕位置并分配给玩家飞船
gameObject.transform.position=
CameraObject.ScreenToWorldPoint(screenPosition);}
//从屏幕到底部
否则如果(屏幕位置y<0){
//夹紧(复位)到屏幕底部
屏幕位置y=0;
//将屏幕位置转换为世界空间,并将玩家分配给飞船
gameObject.transform.position=
CameraObject.ScreenToWorldPoint(屏幕位置);
void FixedUpdate()
if(Input.GetKey.(KeyCode.T)){
rb.AddForce(0,0,推进器速度,ForceMode.pulse);}
//根据inout中的“Fire1”更新船舶的射击
void UpdateFiring(){
//每帧累积时间,当按下fire键时,我们检查是否经过足够的时间。
FireTimer+=Time.deltaTime;
//检测是否按下了点火按钮。
if(Input.GetButton(“Fire1”){}
//发射时间是否超过了发射物产卵之间的时间?
如果(FireTimer>FireRate){}
//重置计时器,使其在下一次放炮时从头开始计数。
FireTimer=0;
//调用处理投射物生成的函数。
DoweApponfire();}
//处理投射物的繁殖
void DoWeaponFire(){
//创建一个新的子弹实例,并将其放置在玩家的位置,面向同一方向。
实例化(项目符号、transform.position、transform.rotation);}

}

我没有完全理解您的代码,但通过观察模式,我怀疑您可能遗漏了我所评论位置的几个括号。
if(screenPosition.x>Screen.width){
屏幕位置x=0;
gameObject.transform.position=CameraObject.ScreenToWorldPoint(screenPosition);}

else if(screenPosition.x<0)//在这里,使用正确的干净格式的代码将对您有所帮助。。请试着理解如何修复您所写的内容。。这是C#而不是javascript风格的编码。。