Problem with return value combined with passing a variable through scripts.
I am making a small game where the player needs to answer questions by dragging characters to a bucket. When spawning my characters I add an ID by passing a variable to another script which checks if the ID of the character matches the ID of the question. When running the game and looking in the inspector shows that all ID's are 0, when they should be 0 through 9 (one per spawned character). I got the feedback to return the passed variable but don't understand how that works in combination. I have attached my code below. It is my first time posting here so let me know if this is enough info.
QuestionAnswerList script
foreach (var item in answerText)
{
savedPosition = new Vector3(Random.Range(9, -9), 1, Random.Range(9, -9));
Instantiate(myPrefab, savedPosition, Quaternion.identity);
myPrefab.GetComponentInChildren<TextMeshPro>().text = answerText[answerNumber].ToString();
answerNumber++;
bucketTrigger.UpdateIndexNumberCheck(answerIndex);
answerIndex++;
}
BucketTrigger script
void Update()
{
answerIndexNumberCheck = UpdateIndexNumberCheck();
}
public int UpdateIndexNumberCheck(int answerIndex)
{
return answerIndex;
}
void OnTriggerEnter(Collider other)
{
if (answerIndexNumberCheck == 1)
{
Debug.Log("Test");
}
}
It now gives the error:
BucketTrigger.cs(22,34): error CS7036: There is no argument given that corresponds to the required formal parameter 'answerIndex' of 'BucketTrigger.UpdateIndexNumberCheck(int)'
Line 22 being: answerIndexNumberCheck = UpdateIndexNumberCheck();
Your answer
Follow this Question
Related Questions
Get all Child Transforms in Target 2 Answers
Get Set Return method, properties stuff? 2 Answers
Premature level loading. String loads level, instead of Return key. 2 Answers
return characters ? 0 Answers
Return in c# 1 Answer