错误CS0119:表达式表示“类型';,其中“变量'`值';或“方法组';预期

本文关键字:方法 预期 方法组 变量 其中 类型 表达式 CS0119 错误 表示 | 更新日期: 2023-09-27 18:00:08

编写一个稍后将链接到按钮的脚本。这个脚本会检查物品是否已经购买,如果没有,允许购买比做一些基本的计算。不知道为什么,但在每个函数的同一行,我都会得到错误。它通常是if语句的第一行。这是:

Assets/Scripts/purchaseScript.cs(25,51):错误CS0119:表达式表示type', where a变量",value' or方法组"应为

这是剧本。

using UnityEngine;
using System.Collections;
public class purchaseScript : MonoBehaviour {
    //Imported Scripts
    public cameraspeed cs;
    //prices
    public int greenBallPrice = 100;
    public int blueBallPrice = 100;
    public int purpleBallPrice = 350;
    public int pinkBallPrice = 350;
    public int rainbowBallPrice = 1000;
    public int peaceBallPrice = 1800;
    public int yingyangBallPrice = 1800;
    public int hashtagBallPrice = 2000;
    public int oceanBallPrice = 2400;
    public int speakerBallPrice = 2400;
    //has been purchased booleans arent being used, instead, using playerPrefs int (1/0 = true/false)
    //Purchase Scripts
    public void buyGreen(){
        if(cs.balance > greenBallPrice || balance == greenBallPrice && PlayerPrefs.HasKey("greenOwned") == false){
            cs.balance -= greenBallPrice;
            //insert logic for setting image here
            //Logging that it was purchased to playerPrefs
            PlayerPrefs.SetInt("greenOwned", 1);
        }
    }
    public void buyBlue(){
        if(cs.balance > blueBallPrice || balance == blueBallPrice && PlayerPrefs.HasKey("blueOwned") == false){
            cs.balance -= blueBallPrice;
            //insert logic for setting image here
            //Logging that it was purchased to playerPrefs
            PlayerPrefs.SetInt("blueOwned", 1);
        }
    }
    public void buyPurple(){
        if(cs.balance > purpleBallPrice || balance == purpleBallPrice && PlayerPrefs.HasKey("purpleOwned") == false){
            cs.balance -= purpleBallPrice;
            //insert logic for setting image here
            //Logging that it was purchased to playerPrefs
            PlayerPrefs.SetInt("purpleOwned", 1);
        }
    }
    public void buyPink(){
        if(cs.balance > pinkBallPrice || balance == pinkBallPrice && PlayerPrefs.HasKey("pinkOwned") == false){
            cs.balance -= pinkBallPrice;
            //insert logic for setting image here
            //Logging that it was purchased to playerPrefs
            PlayerPrefs.SetInt("pinkOwned", 1);
        }
    }
    public void buyRainbow(){
        if(cs.balance > rainbowBallPrice || balance == rainbowBallPrice && PlayerPrefs.HasKey("rainbowOwned") == false){
            cs.balance -= rainbowBallPrice;
            //insert logic for setting image here
            //Logging that it was purchased to playerPrefs
            PlayerPrefs.SetInt("rainbowOwned", 1);
        }
    }
    public void buyPeace(){
        if(cs.balance > peaceBallPrice || balance == peaceBallPrice && PlayerPrefs.HasKey("peaceOwned") == false){
            cs.balance -= greenBallPrice;
            //insert logic for setting image here
            //Logging that it was purchased to playerPrefs
            PlayerPrefs.SetInt("peaceOwned", 1);
        }
    }
    public void buyYingYang(){
        if(cs.balance > yingyangBallPrice || balance == yingyangBallPrice && PlayerPrefs.HasKey("yingyangOwned") == false){
            cs.balance -= yingyangBallPrice;
            //insert logic for setting image here
            //Logging that it was purchased to playerPrefs
            PlayerPrefs.SetInt("yingyangOwned", 1);
        }
    }
    public void buyHashtag(){
        if(cs.balance > hashtagBallPrice || balance == hashtagBallPrice && PlayerPrefs.HasKey("hashtagOwned") == false){
            cs.balance -= hashtagBallPrice;
            //insert logic for setting image here
            //Logging that it was purchased to playerPrefs
            PlayerPrefs.SetInt("hashtagOwned", 1);
        }
    }
    public void buyOcean(){
        if(cs.balance > oceanBallPrice || balance == oceanBallPrice && PlayerPrefs.HasKey("oceanOwned") == false){
            cs.balance -= oceanBallPrice;
            //insert logic for setting image here
            //Logging that it was purchased to playerPrefs
            PlayerPrefs.SetInt("oceanOwned", 1);
        }
    }
    public void buySpeaker(){
        if(cs.balance > speakerBallPrice || balance == speakerBallPrice && PlayerPrefs.HasKey("speakerOwned") == false){
            cs.balance -= speakerBallPrice;
            //insert logic for setting image here
            //Logging that it was purchased to playerPrefs
            PlayerPrefs.SetInt("speakerOwned", 1);
        }
    }

}

错误CS0119:表达式表示“类型';,其中“变量'`值';或“方法组';预期

在第一个if语句中,您可能想要更改

balance == blueBallPrice

cs.balance == blueBallPrice

与其他if语句相同/相似