Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
This question was closed Nov 12, 2015 at 06:50 PM by Blade666 for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by Blade666 · Nov 12, 2015 at 06:25 PM · javascripterrorvariableintcoin

Error BCE0051 with script JS

i am getting the following error Assets/Coin.js(10,10): BCE0051: Operator '+' cannot be used with a left hand side of type 'MenuShopSystem' and a right hand side of type 'int'. I got the variable from the shop script

Coin Script

 #pragma strict
 
 var Money : MenuShopSystem ;
 function Start () {
 
 }
 
  function OnCollisionEnter ( )
  {
    Money += 100;
    GameObject.Destroy ( gameObject ) ;
  
  }



Shop Script if it helps #pragma strict //add this script to any gameObject you want//

 //paste this to add more items to youre shop:
 // if(GUI.Button(Rect(Screen.width/2,Screen.height/2,150,150), Item)){
 // if(Money >= 200){
 // Money -= 200;
 // }else{
 // Money -=0;
 // }
 // }
 // GUI.Button(Rect(Screen.width/2+150,Screen.height/2,150,150), "Buy: 200");
 
 
 
 //variables----------------------------------------
 var ShowShop = false;
 var CoinTexture : Texture;
  public var Money :int=0;
 var skin : GUISkin;
 var AddButton = false;
 //Items:
 //to add more items just copy this variable and add the item name;
 
 var Item : Texture;
 var Item2 :Texture;
 var Item3 :Texture;
 
 //code----------------------------------------
 function Start () {}
 
 function Update () {
 if(Money <= 0){
 Money = 0;
 }
 }
 
 function OnGUI(){
 GUI.skin = skin;
 if(ShowShop ==true){
 //money{********************-------------------------------------------------------------**************************
 GUI.Button(Rect(Screen.width/60,Screen.height/60  ,50,50), CoinTexture);
 GUI.Button(Rect(Screen.width/60+50,Screen.height/60  ,70,50), ""+Money);
 if(AddButton ==true){
 if(GUI.Button(Rect(Screen.width/60+120,Screen.height/60  ,70,50), "Add")){
 Money += 100;
 }
 }
 //money}***********************-------------------------------------------------------------------*****************************
 
 //Items(Shop){
 if(GUI.Button(Rect(Screen.width/2,Screen.height/2,150,150), Item)){
 if(Money >= 200){
 Money -= 200;
 }else{
 Money -=0;
 }
 }
 GUI.Button(Rect(Screen.width/2+150,Screen.height/2,150,150), "Buy: 200");
 
 if(GUI.Button(Rect(Screen.width/2,Screen.height/2- -150,150,150), Item2)){
 if(Money >= 150){
 Money -= 150;
 }else{
 Money -=0;
 }
 }
 GUI.Button(Rect(Screen.width/2+150,Screen.height/2- -150,150,150), "Buy: 150");
 
 if(GUI.Button(Rect(Screen.width/2,Screen.height/2- 150,150,150), Item3)){
 if(Money >= 500){
 Money -= 500;
 }else{
 Money -=0;
 }
 }
 GUI.Button(Rect(Screen.width/2+150,Screen.height/2- 150,150,150), "Buy: 500");
 //Items(Shop)}
 
 
 }
 }//OnGUI End////////////////////////////////////
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

  • Sort: 
avatar image
0
Best Answer

Answer by Landern · Nov 12, 2015 at 06:30 PM

Money is the name of the variable that is of type MenuShopSystem, you want to modify the value of the field called Money that is in the MenuShopSystem script.

So you would do the object name(in this case you made the variable called Money)

 Money
 ^-- Variable name of type MenuShopSystem

and you want to modify the value of Money which just happens to be called the same as the variable name.

 Money.Money += 100;
       ^---- the field you want to modify that is in the type MenuShopSystem but you're modifying the object you instantiated in coin.js.


Money as the variable name that you're instantiating could be called buttsystem for all the script cares when creating an instance of MenuShopSystem.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Blade666 · Nov 12, 2015 at 06:49 PM 0
Share

Thank you so much :) I appreciate it. I have also rewarded you @Landern

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Help with JS script 0 Answers

Javascript error 1 Answer

NullReferenceException: Object reference not set to an instance of an object 1 Answer

Not compiled 1 Answer

Slicing an int in js/unityscript? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges