- Home /
Trying to count objects In order and have them disappear. Then have a Teleport Point Appear.
Hello!
I am trying to create a game for kids to learn their planets! I want it to work where when the player pulls a planet down to the panel and puts it in the cone on the panel (see image), the planet disappears and the number on the panel goes up to let them know it’s the correct planet and to get the next planet. What’s the best way to do this?
Right now I have it set so all the planets disappear when they enter the trigger on the cone (see code below), but it’s not set for a specific order. The order the player inputs the planets into the panel would need to be in order from the sun. (Mercury, Venus, Earth, Mars, Jupiter, Saturn, Uranus, and Neptune) For example, If they pull down Venus before Mercury, the planet won’t disappear because that’s not the right order of the planets! But if they were to put Mercury in the cone, the planet would disappear and text on the panel would change from ‘1’ to ‘2’.
Also I'd like a teleport point to show up after they complete inputting all the planets in order. I have coded all these things separately, but can't figure out how to get it all to work together! Here is all the coding I've done!
TO MAKE THE PLANETS DISAPPEAR ONTRIGGERENTER:
void OnTriggerEnter(Collider other)
{
if (other.gameObject.tag == "Mercury")
{
Debug.Log(other.gameObject.name);
Destroy(other.gameObject, .5f);
}
if (other.gameObject.tag == "Venus")
{
Debug.Log(other.gameObject.name);
Destroy(other.gameObject, .5f);
}
if (other.gameObject.tag == "Earth")
{
Debug.Log(other.gameObject.name);
Destroy(other.gameObject, .5f);
}
if (other.gameObject.tag == "Mars")
{
Debug.Log(other.gameObject.name);
Destroy(other.gameObject, .5f);
}
if (other.gameObject.tag == "Jupiter")
{
Debug.Log(other.gameObject.name);
Destroy(other.gameObject, .5f);
}
if (other.gameObject.tag == "Saturn")
{
Debug.Log(other.gameObject.name);
Destroy(other.gameObject, .5f);
}
if (other.gameObject.tag == "Uranus")
{
Debug.Log(other.gameObject.name);
Destroy(other.gameObject, .5f);
}
if (other.gameObject.tag == "Neptune")
{
Debug.Log(other.gameObject.name);
Destroy(other.gameObject, .5f);
}
TO MAKE THE TELEPORT POINT SHOW UP AFTER PLANETS ARE ALL INPUTTED INTO THE PANEL:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class TeleportBlackHole : MonoBehaviour
{
public static int TriggerCounter = 0;
public GameObject TeleportPointOfChoice;
private void Start()
{
TeleportPointOfChoice.SetActive(false);
}
void OnTriggerEnter(Collider other)
{
TriggerCounter++;
if (TriggerCounter >= 8)
{
ActivateTeleportPoint();
}
}
void ActivateTeleportPoint()
{
TeleportPointOfChoice.SetActive(true);
}
}
MY PROFESSOR GAVE ME THIS CODE BUT I DON'T KNOW HOW TO DO WHAT I WANT TO DO WITH THIS CODE:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using TMPro;
public class PlanetManager : MonoBehaviour
{
public List<GameObject> planets = new List<GameObject>();
public int index = 0;
public TextMeshProUGUI counterText;
private void Start()
{
counterText.SetText(index.ToString());
}
private void OnCollisionEnter(Collision collision)
{
if(collision.gameObject == planets[index].gameObject)
{
index++;
counterText.SetText(index.ToString());
}
else
{
//Whatever you want to have happen if they do this incorrectly
}
if(index >= planets.Count)
{
//Do whatever you want when they put them in
SceneManager.LoadScene("NextScene");
}
}
}
[1]: /storage/temp/136808-screen-shot-2019-04-21-at-40819-pm.png
THANKS FOR YOUR HELP!
Your answer
Follow this Question
Related Questions
'UnityEngine.Component.collider' is obsolute,'UnityEngine.Component.Collider' is obsolete 2 Answers
why doesnt this script work 0 Answers
DllNotFoundException: sqlite3 IOS 0 Answers
Run time counter 1 Answer
Only tagged objects raise counter 1 Answer