Reputation: 27
Writing a script that will later be linked to buttons. This script will check if the item has been purchased, if not, allow the purchase than do some basic math. Not sure why but on the same line of every function I get the error. Its usually the first line of the if statement. Here it is:
Assets/Scripts/purchaseScript.cs(25,51): error CS0119: Expression denotes a
type', where a
variable',value' or
method group' was expected
here is the script.
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);
}
}
}
Upvotes: 1
Views: 7982
Reputation: 3580
On the first if statement, it looks like maybe you want to change
balance == blueBallPrice
to
cs.balance == blueBallPrice
The same/similar with the other if statements
Upvotes: 2