【问题标题】:Error CS1519 - Invalid token 'float' in class, struct or interface member declaration错误 CS1519 - 类、结构或接口成员声明中的令牌“浮动”无效
【发布时间】:2019-08-02 01:43:40
【问题描述】:

我正在创建一个小行星射击游戏,我正在为班级做作业以增加分数。在 Asteroid 脚本中添加“scoreValue”和“playerScript”后,

我现在收到“错误 CS1519 - 类、结构或接口成员声明中的无效标记 'float'”

这是我当前的错误代码:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class asteroidScript : MonoBehaviour
{
    public float speed;
    public Transform explosion;
    private asteroidScript scriptAsteroid;
    public int scoreValue;
    public playerScript 

    //my screen size limits
    float minX = -12.72f,
         maxX = 12.72f,
         minY = -11.89f,
         maxY = 11.89f;
    float startY, endY;
    private int newScoreValue;

    // Start is called before the first frame update
    void Start()
    {
        startY = maxY + 3; //initializing start point for asteroid
        endY = minY + -3; // initializing end point for asteroid
    }

    // Update is called once per frame
    void Update()
    {
        transform.Translate(Vector3.down * speed * Time.deltaTime);
        //check if I passed the bottom of the screen
        if (transform.position.y < minY)
        {
            //function call
            resetEnemy();
        }

    }

    public void resetEnemy()
    {
        //Reset the position of the asteriods
        Vector3 position = transform.position;
        position.y = startY;
        //randomly choose my x position
        position.x = Random.Range(minX, maxX);
        //put the asteroid at that position
        transform.position = position;
    }
    void OnTriggerEnter(Collider other)
    {

        //I am going to check what I collided with
        if (other.gameObject.tag == "Asteroid")
        {
            //Reposition the asteroid to the top of the game
            //get the asteriod Script
            scriptAsteroid = other.GetComponent<asteroidScript>();
            //call the function to reset asteroid
            scriptAsteroid.resetEnemy();
            //create explosion
            Instantiate(explosion, transform.position, transform.rotation);
            //reset myself - the asteroid
            resetEnemy();
        }
        //I am going to check if I collided with the player
        if(other.gameObject.tag == "Player")
        {
            //create explosion
            Instantiate(explosion, transform.position, transform.rotation);
            //reset myself - the asteroid
            resetEnemy();
            //later I have to code the shield in :)
        }
      { 
        playerScript.AddScore(newScoreValue);
}
    }
}

这是我的代码在进行更改之前没有错误的样子...

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class asteroidScript : MonoBehaviour
{
    public float speed;
    public Transform explosion;
    private asteroidScript scriptAsteroid;
    //my screen size limits
    float minX = -12.72f,
         maxX = 12.72f,
         minY = -11.89f,
         maxY = 11.89f;
    float startY, endY;
    // Start is called before the first frame update
    void Start()
    {
        startY = maxY + 3; //initializing start point for asteroid
        endY = minY + -3; // initializing end point for asteroid
    }

    // Update is called once per frame
    void Update()
    {
        transform.Translate(Vector3.down * speed * Time.deltaTime);
        //check if I passed the bottom of the screen
        if (transform.position.y < minY)
        {
            //function call
            resetEnemy();
        }

    }

    public void resetEnemy()
    {
        //Reset the position of the asteriods
        Vector3 position = transform.position;
        position.y = startY;
        //randomly choose my x position
        position.x = Random.Range(minX, maxX);
        //put the asteroid at that position
        transform.position = position;
    }
    void OnTriggerEnter(Collider other)
    {

        //I am going to check what I collided with
        if (other.gameObject.tag == "Asteroid")
        {
            //Reposition the asteroid to the top of the game
            //get the asteriod Script
            scriptAsteroid = other.GetComponent<asteroidScript>();
            //call the function to reset asteroid
            scriptAsteroid.resetEnemy();
            //create explosion
            Instantiate(explosion, transform.position, transform.rotation);
            //reset myself - the asteroid
            resetEnemy();
        }
        //I am going to check if I collided with the player
        if(other.gameObject.tag == "Player")
        {
            //create explosion
            Instantiate(explosion, transform.position, transform.rotation);
            //reset myself - the asteroid
            resetEnemy();
            //later I have to code the shield in :)
        }
    }
}

我看不到出了什么问题,以及为什么“Float”现在被声明为无效标记。任何解决方案都是最有帮助的!谢谢!

  • 贾斯汀

【问题讨论】:

  • public playerScript -- 缺少分号。如果您遇到“意外等等”错误,请在之前的行中查找缺少的分号。
  • 谢谢!我是个业余爱好者,经常看不到最简单的变化。编码不是我的强项。我很感激。
  • public playerScript 后面缺少分号
  • 别担心 - 这是一个诀窍。一段时间后,您开始看到不存在的标点符号。不幸的是,我不认为这是一种可转移的技能......

标签: c# interface declaration


【解决方案1】:

你应该在第 9 行声明“public playerScript”后使用 ";" 这是一个常见的缺少分号 我知道它很晚,但我希望其他人可以使用它

【讨论】:

    猜你喜欢
    • 2020-03-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多