• 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 /
avatar image
0
Question by Nurmerman · Jun 22, 2020 at 02:53 PM · scripting problem

array of gameobjects

So I have a script for the amount of money and apples I have in my game and want to make more than 1 gameobject have the amount of apples script. btw there IS a void TransferMoney and IS public. I do this, and I need to transfer the amount of money i have to the apple script but because it's an array it does the following error: (55,16): error CS1061: 'apple[]' does not contain a definition for 'TransferMoney' and no accessible extension method 'TransferMoney' accepting a first argument of type 'apple[]' could be found (are you missing a using directive or an assembly reference?) Here's the money script: using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using TMPro; using UnityEngine.SceneManagement;

public class numberofmoney : MonoBehaviour //script in the Text UI "amount of money" {

 static public int scenemoney;
 public string house;
 public string shopString;
 
 public TMP_Text moneyText;
 public cookie1 Cookie;
 public apple[] apples;

 public void BoughtApple(int currentAOM)//aom stands for 'amount of money'
 {
     scenemoney = currentAOM;
 }

 void Awake()
 {
     apples = GameObject.FindObjectsOfType<apple>();  //finds apple
 }

 void Start()
 {
     Scene cookie = SceneManager.GetActiveScene();
     house = cookie.name;    //checks scene and does part of converting to string

     Scene shop = SceneManager.GetActiveScene();
     shopString = shop.name; //checks scene and does part of converting to string
 
 }

 public void forCookie(int money)
 {
     scenemoney = money;
 }

 void Update()
 {

     string scenemoneystring = scenemoney.ToString();
     moneyText.SetText(scenemoneystring); //Converts money and sets text

     if (house == "House") {     //transfers money between scripts #1
     Cookie.transferMoney(scenemoney);
     }

     if (shopString == "store") { //transfers money between scripts #2
     apples.TransferMoney(scenemoney);
     }
 }

 

}

and apples script:

using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using TMPro;

public class apple : MonoBehaviour {

 public string appleString;
 public int publicMoney;
 public int Apples;

 public NumberOfApples numberOfApples;
 public TMP_Text tmp;
 public numberofmoney NumberOfMoney;

 void Awake()
 {
     numberOfApples = GameObject.FindObjectOfType<NumberOfApples>();
     NumberOfMoney = GameObject.FindObjectOfType<numberofmoney>();
 }

 public void TransferMoney(int money) 
 {
     publicMoney = money;
 }

 void OnTriggerEnter2D(Collider2D trigger)
 {
     if (publicMoney >= 10){
         Destroy(this.gameObject);
         Apples++;
         publicMoney -= 10;
         appleString = Apples.ToString();
         tmp.SetText(appleString);
         NumberOfMoney.BoughtApple(publicMoney);
     }

     numberOfApples.transferApples(Apples);
 }

 void Update()
 {
 }

}

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

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

229 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Directly assigning Material through Renderer.materials doesn't work 2 Answers

Change two shader color with script 0 Answers

How to make W button move towards mouse direction 1 Answer

OnMouseDown only works once 1 Answer

On/Off Trigger is making Light Flicker 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