首页 > 解决方案 > 为什么这会给我一个错误,在类、结构或接口成员声明中说意外符号“1”

问题描述

我制作了一个游戏,这个游戏突然出现了

我从其他地方看,没有找到答案

唱 UnityEngine;使用 System.Collections;

公共课 pyssy : MonoBehaviour {

public int bulletsPerMag = 30;
public int bulletsLeft;

public float fireRate = 0,1f;

float fireTimer;

// Use this for initialization
void Start () {

}

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

    if (Input.GetButton("Fire1"))
    {
        Fire();
    }

    if (fireTimer < fireRate)
        fireTimer += Time.deltaTime;

}

private void Fire()
{
    if (fireTimer < fireRate) return;
    Debug.Log("shot!")
}

}

应该管用

标签: unity3d

解决方案


public float fireRate = 0,1f;对于浮点值,您应该使用点而不是逗号。编程中的逗号用于分隔不同的值。

将其更改为public float fireRate = 0.1f;

并给你一个提示。当您遇到unexpected symbol/character错误或类似情况时,通常意味着它要么是拼写错误,要么是没有正确结束的行。至少我有好几次都是这样!


推荐阅读