I have a game in which 2 prefabs are created: an order and a dish.
Each prefab has its own script.
In the CreateQuestion function, 6 types of dishes and 6 orders are created. The correct pairs must be connected. And after the correct answer, delete it.
So far, I can remove the feedback and the dish itself, but not the order. How can i do this?
This code of GameManager
public class GameManagerScript : MonoBehaviour
{
//game
[SerializeField] private QuestionClass myQuestion;
[SerializeField] private Dishes dishObject;
[SerializeField] private Orders orderObject;
[SerializeField] private TextMeshPro questionTextBox;
[SerializeField] private float ansDistance;
public bool isMatch;
public List<Transform> orderPosList;
[System.Serializable]
public class QuestionClass
{
public string questionText;
public List<AnswerClass> orders;
public List<AnswerClass> dishes;
}
[System.Serializable]
public class AnswerClass
{
public string content;
public int mathPair;
}
public void CreateQuestion()
{
questionTextBox.text = myQuestion.questionText;
for (int i = 0; i < myQuestion.orders.Count; i++)
{
Dishes newObj = Instantiate(dishObject, new Vector2(transform.position.x + (i*ansDistance),transform.position.y), Quaternion.identity);
newObj.ansContentText.text = myQuestion.orders*.content;*
newObj.MatchPair = myQuestion.orders*.mathPair;*
newObj.myDishes = newObj.gameObject;
}
for (int i = 0; i< 3; i++)
{
Orders newObj = Instantiate(orderObject, orderPosList*.position, Quaternion.identity);*
newObj.ansContentText.text = myQuestion.dishes*.content;*
newObj.MatchPair = myQuestion.dishes*.mathPair;*
newObj.myOrder = newObj.gameObject;
}
}
}
This code of Prefab Dishes
public class Dishes : MonoBehaviour
{
public TextMeshPro ansContentText;
public int MatchPair;
public bool isMatch;
public GameObject feedbackFalse;
public GameObject feedbackTrue;
public bool isConnect = false;
public Transform Feedback;
public GameManagerScript myManager;
[SerializeField] private Orders orderObject;
public GameObject myDishes;
public void Update()
{
if (Input.GetKeyDown(KeyCode.Space) && isConnect == true)
{
if (isMatch == true)
{
ShowCorrect();
}
else
{
ShowIncorrect();
}
}
}
public void OnTriggerEnter2D(Collider2D other)
{
Orders order = other.GetComponent();
Dishes dishes = GetComponent();
if (order != null && dishes != null)
{
isConnect = true;
if (order.MatchPair == dishes.MatchPair)
{
isMatch = true;
Debug.Log(“Match”);
}
else
{
isMatch = false;
Debug.Log(“NoMatch”);
}
}
}
public void ShowCorrect()
{
Vector2 positionF = Feedback.position;
GameObject feedbackTrueInstance = Instantiate(feedbackTrue, positionF, transform.rotation);
isConnect = false;
Destroy(feedbackTrueInstance, 4);
Destroy(myDishes, 4);
}
public void ShowIncorrect()
{
Vector2 positionF = Feedback.position;
GameObject feedbackFalseInstance = Instantiate(feedbackFalse, positionF, transform.rotation);
isConnect = false;
Destroy(feedbackFalseInstance, 4);
}
}
This code of Orders
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
public class Orders : MonoBehaviour
{
public TextMeshPro ansContentText; //גישה לטקסט בתוך התשובה
public int MatchPair; //משתנה בוליאני
public GameObject myOrder;
}
Thank you!