How does one make an object appear after completing an objective.
So I have no idea how to make scripts and I have looked around, but have not found what I am looking for in particular. I need a way to make one of my objects (a teleporter) appear after picking up a coin. This way the character or player can teleport to the next level. This is the tutorial area I am working with and was wondering how to make this happen. Thanks!
Is the teleporter already there and just invisible? or do you want it to be created from a prefab?
Okay first off, I need you to adopt a new $$anonymous$$dset. If you have a task, break it down into smaller steps. If you're unsure of how to complete some of these steps, break it down further. With that being said your task is to make a Teleporter appear after picking up a coin correct?
So how would we pick up a coin? It would be simple to us, although in game development sometimes wee have to cut corners. So lets break it down into smaller steps. In $$anonymous$$ario, coins are present, but once you touch a coin it disappears. Let's do that.
First the coin is existing, and then once we touch it, it's gone. Touching works through colliders. So I would have the coin contain a script to constantly check if it's colliding with something. And once it does we destroy it. There by "Picking it up." To accomplish this i would start off by having this snippet:
void OnCollisionEnter ( Collision collision )
{
Destroy(this.gameObject);
}
Hold this $$anonymous$$dset and build your knowledge with it. I hope this information helps you and gives a starting point in scripting and the awesome world in game development.
Okay. So I already have a personal script to pick up coins as well as count the coins. I just do not know what form of functions I must create in order to have an object appear after touching that coin. I do not want a script given, but rather a way to understand what I need to do. As I said before I am completely new to scripting and I want to learn. I have looked for tutorials, but all they do is give scripts with no explanation. I want some help understanding the functions and how to complete this task thats all. Thanks!
Answer by EpicPandaGamer25 · Dec 31, 2015 at 07:25 PM
@ Jlmccart01
Put this on your coin pickup script(should be on your player):
//New Variables
public GameObject teleporter; //Assign this gameObject in the inspector
void OnTriggerEnter (Collider col) {
if (col.gameObject.name == "COINNAMEHERE") { //COINNAMEHERE should be the name of your coin gameObject
coins += 1; //Whatever your coin counter variable is replace coins with that
Destroy(col.gameObject);
teleporter.SetActive(true); //Make sure that the teleporter is disabled by default in the inspector
}
}
So what would the coin counter variable be? I am new to all this ter$$anonymous$$ology and I have tried everything, but I cannot figure out what I should be putting there to get the script to work?
So this is the code that I have modified a little, but I keep getting errors especially with the coin += 1 as it does not like the += part. Am I confusing something here?
using UnityEngine; using System.Collections;
public class TeleporterAppear : $$anonymous$$onoBehaviour {
public GameObject coin;
public GameObject teleporter;
void OnTriggerEnter (Collider col) {
if(col.gameObject.name == "Coin") {
coin += 1;
Destroy (col.gameObject);
teleporter.SetActive (true);
}
}
}