• 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 cidmodder · Mar 01, 2012 at 04:43 PM · c#arrays

The member `Clock.creaturesArray' cannot be used as method or delegate

I was looking around and couldn't find an answer to what the above error means. I am trying to send a message in a script to the first object in an array and I get this error at the send message. Here's the script.

 using UnityEngine;
 using System.Collections;
 
 public class Clock : MonoBehaviour {
 
     public int hour;
     public int minute;
     public int second;
     public bool PM;
     public int n;
     public ArrayList playerCreatures;
     public object[] creaturesArray;
     
     // Use this for initialization
     void Start () {
     
         hour = 12;
         minute = 0;
         PM = false;
         second= 0;
         n=1;
         playerCreatures.Add(GameObject.Find("Bullark_Elec_v1"));
         creaturesArray = playerCreatures.ToArray();
         
     }
     
     // Update is called once per frame
     void Update () {
     
         if ( Time.time >= second){
             second ++;
             minute++;    
             
         }
         
         if ( minute == 60){
             hour++;
             minute = 0;    
             
         }
         if (hour > 23){
         hour = 0;    
             
         }
     
         if ( second == n*4){
             
             
             creaturesArray(1).SendMessage(Stamina, hour);
             
             n++;
             
         }
     }
 }

thanks for an explanation!

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

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Bunny83 · Mar 01, 2012 at 04:59 PM

First of your creatureArray is of type "object". An Object doesn't have a SendMessage function. It should be of type GameObject since SendMessage is a function of GameObject.

Your actual problem is that you used round brackets which are only used for methods. You need square brackets [].

creaturesArray[1].SendMessage(Stamina, hour);

Keep in mind that index 1 is the second object in the array. 0 is the first one. Also don't forget if you try to use an index that doesn't exist you'll get a runtime error.

edit
Well, another problem is this line:

creaturesArray = playerCreatures.ToArray();

because you use the ArrayList. The ArrayList class stores untyped objects. You better use a generic list instead:

public List<GameObject> playerCreatures;

Don't forget to include this namespace:

using System.Collections.Generic;

I don't get why you even use a containerclass. It contains one element, so you can just put it into the array.

In Start() you can do this:

creaturesArray = new GameObject[] { GameObject.Find("Bullark_Elec_v1") };

or

creaturesArray = new GameObject[1];
creaturesArray[0] = GameObject.Find("Bullark_Elec_v1");

If you plan to store more than one object, you can just use the List<>. Why do you even use an array? ;)

Comment
Add comment · Show 3 · 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 cidmodder · Mar 02, 2012 at 04:00 PM 0
Share

i keep getting this error though when i put it as a GameObject. I think thats why i changed it to object Cannot implicitly convert type object[]' to UnityEngine.GameObject[]'. An explicit conversion exists (are you missing a cast?)

avatar image Bunny83 · Mar 03, 2012 at 02:05 PM 0
Share

I've edited my answer ;)

avatar image cidmodder · Mar 05, 2012 at 03:40 PM 0
Share

Thanks that worked! i do want to add more creatures eventually thats why i needed a list :)

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

6 People are following this question.

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

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

MissingComponetException error 3 Answers

JesseEtzler's RPG Talent System in C# 1 Answer

Dungeon crawler problem(getting transform data from an array) 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