- Home /
i want the player to match 5 items correctly before next scene appears.
i currently have scenes where the player needs to move the correct object to the drop zone before the next scene appears. now i want scenes where the player needs to move all 5 objects to the correct drop zones before the next scene button appears but i cant figure it out.
i dont know how to make a condition that all 5 objects need to be matched correctly first before the button for the next scene appears.
i use a tag on my object and when matched it activates the next scene button, so if i have 5 objects all using the same tag how do i delay the button from activiating till all the objects are in the drop zone, now the button appears after the first object is matched.
public class TriggerButton : MonoBehaviour { public GameObject Player;
private void OnTriggerStay(Collider other)
{
if (other.gameObject.tag == "Player")
if (Input.GetMouseButtonUp(0))
{
{
Player.gameObject.SetActive(true);
}
}
Answer by HellsHand · Apr 15, 2021 at 10:33 PM
Put this into the objects to be matched:
Object Script:
public class MatchedObjects()
{
bool matched = false;
public bool GetMatched() //Sorry I forget, but there is a better get;set method but this works
{
return matched;
}
public void SetMatched()
{
matched = true;
}
}
Then you could use this in the script where you match an object:
public void OnMatch()
{
GameObject[] matchedObjects = GameObject.FindGameObjectsWithTag("Tag"); //Get all objects that need to be matched
foreach(GameObject matchObj in matchedObjects) //Loop through each object
{
if(!matchObj.GetComponent<MatchObjects>().GetMatched()) //If an object doesn't match...
{
break; //This will immediately leave the loop
}
ActivateButton(); //Generic method to activate your button, this will only occur if all tagged objects are matched
}
}
Finally wherever you are actually checking if your objects match, if they do:
"Reference to Object".SetMatch(); //Whatever you use to reference the script for the matched objects
OnMatch(); //Probably on Player I'd guess? Not enough code for a complete answer sorry, but this should get you close, if not post the rest of your scripts and I can tell you where it can go.
thank you so much for your help, the last post worked, i deleted it by accident.
Your answer
Follow this Question
Related Questions
If GameObject with tags not on scene 1 Answer
Count >= then object tag becomes active 1 Answer
How to transform scene object movement in multi player? 0 Answers
Activating Game Objects 3 Answers