- Home /
Spawn Sytem and collider-Trigger to disabling / re-enabling same Collider in a While
I want a trigger-collider to my Spawn script which will then be a area. so when you have triggered then the same Collider will become disable for a while (like maybe 20 minuits, more or less) and comes back up
if I do a example to example it,
I have a house, inside the house I have 3 spawns and as soon as you walk into the house then it will spawn from the 3 spawns. you go in and take them. you should not be able to walk out of the house and back in and get 3 things again,but I'll still be able to go into the house but then it will not spawn anything for you have to wait maybe 20 minutes before you can go into the house again and it will then spawns 3 things again And if you go in to the house before 20 minutes has gone, there will not be any items, because the Collider should be disabled.
So now I wonder if you can the solution for it to work :)
BIG ThX to you who will help me, Really appreciate it :)
how should the entire script look like
This site does not write scripts for you. We help you solve single, specific technical issues to help you write your own code. So you need to boil this question down to a single specific question. $$anonymous$$aybe you just want to know how to turn a collider off for 20 $$anonymous$$utes. $$anonymous$$nowing that, could you then expand your code?
yes thats is what i whant i need the Collider to disable in 20 $$anonymous$$ and then com back up and my Spawn skript gona be trigged when the collider enter i have tryd 3 deferent script to use in this but dosent work out . it need not be in the same script as the spawn script but the 2 scripts need to be in the same as collider script
I have tried with this code: but do not really know where they should be located, or if they should be a single script
....................................................
float timeNextAvailable = 0f;
public float timeBetweenSpawns = 1200.0f;
function OnTriggerEnter () {
if( timeNextAvailable <= Time.time ) {
timeNextAvailable = Time.time + timeBetweenSpawns;
}
And .......................................................
float timeLastTriggerd = float.NegativeInfinity;
function OnTriggerEnter () {
if( timeLastTriggered <= Time.time - 1200.0f ) {
timeLastTriggered = Time.time;
}
and this, also tried and change it to collider :/ ...........................................................
function OnTriggerEnter () {
gameObject.transform.collider.isTrigger = false;
Invoke("HouseEnterTimer", 1200); //1200 seconds is equivalent to 20 $$anonymous$$utes.
}
function HouseEnterTimer () {
gameObject.transform.collider.isTrigger = true;
}
I have said this before (4 days ago, on an earlier question you had about the same topic), take some time to actually learn Unity and UnityScript. This is really a simple problem if you knew a bit about the engine you were working with. You have been stuck on it for 9 days because you continue to try to copy code from answers given to you without actually learning from the helpful answers given to you.
This should not be a 9 day problem, and it will only get harder from here. Read, Learn, and come back when you break your problem down into smaller parts that could be answered without someone having to write all your code for you.
I am learning myself. but it also takes time.
I learn from this page:
http://unity3d.com/learn/tutorials/modules/beginner/scripting
Answer by robertbu · Apr 28, 2014 at 03:21 PM
Here is the logic for turning your collider off and then back on 20 minutes later. Put these lines in the script where you want to disable the collider:
collider.enabled = false;
Invoke("ColliderOn", 1200.0);
Add this function:
function ColliderOn() {
collider.enabled = true;
}
You won't come far with this approach.
var spawnPoints : SpawnPoint[];
class SpawnPoint{
var spawnTransform : Transform;
var prefabs : GameObject[];
}
function OnTriggerEnter(other : Collider){
if(other.collider.tag == "Player") {
Spawn();
}
}
function Spawn(){
for(var spawn : SpawnPoint in spawnPoints){
var obj : GameObject = spawn.prefabs[Random.Range(0, spawn.prefabs.length)];
Instantiate(obj, spawn.spawnTransform.position, spawn.spawnTransform.rotation);
}
collider.enabled = false;
Invoke("ColliderOn", 1200.0);
}
function ColliderOn() {
collider.enabled = true;
}
I saw this problem I got now :/ sorry if i ask / demand too much or even is tedious.
but now I saw that when collidern is enable so of course I can not shoot whit a gun through it.
how can you do so that colliden is disable from the beginning, and then when you go into it so enable it in 1 secund and then become disabled for 20 $$anonymous$$utes.
Based on your comment, I assume you want to shoot through the building. I'm not sure how you have things setup, but can't you just set the 'isTrigger' to true for the collier on the building? Or you can use the Physics.IgnoreCollision() for the bullets and the building, or you can use separate collision layers. The problem with what you outlines is that you need something to detect the player and turn on the collider. Usually this is the job of a collider. I suppose you could use something like Physics.OverlapSphere() to detect the player and turn on the collider, but you won't be assure that he enters the building in one second.
trigger ON, will not work it is already on.
but its no problem i fix it (Y) thx
Your answer
Follow this Question
Related Questions
spawn objects in random locations, check if location already taken 1 Answer
Can someone help me fix my Javascript for Flickering Light? 6 Answers
Script doesn't find other script 0 Answers
Collider Filtering 1 Answer
Need some help an object collider that stops a timer then displays it on another scene 1 Answer