错误CS0119:表达式表示“类型”,其中需要“变量”,“值”或“方法组”

时间:2015-06-28 23:45:13

标签: c# unity3d

编写一个稍后将链接到按钮的脚本。此脚本将检查是否已购买该项目,如果没有,则允许购买而不是一些基本数学。不知道为什么但是在每个函数的同一行我得到了错误。它通常是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);
        }

    }


}

1 个答案:

答案 0 :(得分:1)

在第一个if语句中,看起来好像你想要改变

balance == blueBallPrice

cs.balance == blueBallPrice

与其他if语句相同/相似

相关问题