错误CS1519-类,结构或接口成员声明中的令牌无效'float'

时间:2019-03-11 17:11:40

标签: c# interface declaration

我正在创建一个小行星射击游戏,并且我正在上课作业以增加得分。在将“ scoreValue”和“ playerScript”添加到Asteroid脚本后,

我现在收到“错误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”声明为无效令牌。任何解决方案将是最有帮助的!谢谢!

  • Justin

0 个答案:

没有答案