using UnityEngine;
using System.Collections;
public class boxesInfo : MonoBehaviour {
public string Word;
public string Color;
private GameObject TheSpawner;
// Use this for initialization
void Start () {
TheSpawner = GameObject.FindGameObjectWithTag("TheSpawner");
}
// Update is called once per frame
void Update () {
}
void Delete ()
{
Destroy (gameObject);
}
void OnMouseDown ()
{
TheSpawner.gameObject.SendMessage ("BoxClicked", Word, Color, SendMessageOptions.DontRequireReceiver);
}
}
And i get this error
Assets/Scripts/boxesInfo.cs(26,39): error CS1501: No overload for method `SendMessage' takes `4' arguments
void BoxClicked(object[] boxInfo) // This is linje 325
{
for (int i = 0; i<10; i++) {
if(boxInfo[0] == Word[i]){
ClickedWord = i;
}
if(boxInfo[1] == Color[i]){
ClickedColor = i;
}
}
Debug.Log ("Clicked Word: " + boxInfo [0] + "( " + ClickedWord + ") Clicked Color: " + boxInfo [1] + "( " + ClickedColor + ") ");
}// This is line 341
And im getting this error
IndexOutOfRangeException: Array index is out of range.
SpawnControls.BoxClicked (System.Object[] boxInfo) (at Assets/SpawnControls.cs:331)
System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:222)
Rethrow as TargetInvocationException: Exception has been thrown by the target of an invocation.
System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo
This is how the Word and color look like, when i want to compare it:
public string[] Word = new string[] {"Black","Blue","Brown","Green","Orange","Pink","Purple","Red","White","Yellow"};
public string[] Color = new string[] {"Black","Blue","Brown","Green","Orange","Pink","Purple","Red","White","Yellow"};
FYI, on SendMessage, the Word and Color is Strings!
using UnityEngine;
using System.Collections;
public class boxesInfo : MonoBehaviour {
public string Word;
public string Color;
private GameObject TheSpawner;
// Use this for initialization
void Start () {
TheSpawner = GameObject.FindGameObjectWithTag("TheSpawner");
}
// Update is called once per frame
void Update () {
}
void Delete ()
{
Destroy (gameObject);
}
void OnMouseDown ()
{
TheSpawner.gameObject.SendMessage ("BoxClicked", new string[]{Word, Color}, SendMessageOptions.DontRequireReceiver);
}
}
LeftRighty no. it should be the lenght of word[ ] or color[ ]
These are the word and color arrays:
public string[] Word = new string[] {"Black","Blue","Brown","Green","Orange","Pink","Purple","Red","White","Yellow"};
public string[] Color = new string[] {"Black","Blue","Brown","Green","Orange","Pink","Purple","Red","White","Yellow"};
You dont need to use string.Compare, == is fine.
The issue seems to be your boxInfo array.
Print out the size of it in a debug statement, it should be 2.
Never used the messagingsystem, it looks rather complicated. The documentation is also lacking i think, there really isnt a demonstration on how to use this.
The error was that the:
string[ ] Word and string[ ] Color
Wasn’t update to its newest editing, so apperently it had only a length of 6, which was the old length.
I deleted all the strings values in the Inspector and changed it by hand