- Home /
Enable an area after a condition is met
i am using Unity 2D and C sharp.
I been trying to make it so a teleporter is disabled by default until you collect a certain item, then it enables it so then when you go to it, it advances you to the next level, I am pretty sure im not even close to doing it right haha.
I know how to switch scenes.
Answer by Vilhien · Jul 17, 2018 at 09:05 PM
Sounds like you'll need the following:
colliders on the object and warp area for collision detection.
You could tag check to make sure its the item or warp on collisions. But this isn't the only way to do so of course.
void oncollisionenter2D (collision2D other) {if (other.tag="Item") --- check if its the item, a tag would have to be setup for this on the item set to the tag. warp.setEnabled=true; -upon colliding with the item, (obtaining it persey (deactivate it destroy etc whatever you prefer)) enabled the warp; -no real bool needed its set upon collision. if(other.tag="warp") -no chance for collision because it won't appear until the item is collided with. do your scene transition here abouts.
Now if you want the warp to always be there, you could change the enabled part of the warp to check a bool instead. (itemfound==true) - or however you'd like to word it.
The "teleport" is more like you going to that area and the scene switches to the next level lol. I already got the item to destroy after colliding with it. I need the teleport area to start as disabled so going to it before collecting the item won't switch scene.
Hey there Crow,
Then start a bool as false on the warp that sets to true upon the destroy of the item collected?
Answer by look001 · Jul 17, 2018 at 09:06 PM
You can enable and disable each level in one scene. For better performance you can also Instantiale the level in the scene or use muliple scenes foreach level. For the Item you probably want to use a sphere collider on the item gameobject as a trigger. With OnTriggerEnter you can Enable the portal with GameObject.SetActive. Good succeed it's all learning by doing!
I got the item to destroy itself after colliding with it. And the "teleport" thing is just an area where after you collect the item, it enables it to switch to the next scene when you go to the teleport area. I need the teleport area to start as disabled so going to it before collecting the item won't switch scene.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
How to attract multiple objects to a target object? C#, 3 Answers
Initialising List array for use in a custom Editor 1 Answer
How to create a Drag & Drop system which verifies what gameObject was dragged into the slot? 0 Answers