Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by The-W.A.T.Z.R · Apr 28, 2014 at 02:53 PM · javascriptcolliderwhile loop

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 :)

Comment
Add comment · Show 4
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image robertbu · Apr 28, 2014 at 03:06 PM 2
Share

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?

avatar image The-W.A.T.Z.R · Apr 28, 2014 at 03:14 PM 0
Share

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;
 
 }
avatar image roojerry · Apr 28, 2014 at 04:20 PM 0
Share

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.

avatar image The-W.A.T.Z.R · Apr 28, 2014 at 04:47 PM 0
Share

I am learning myself. but it also takes time.

I learn from this page:

http://unity3d.com/learn/tutorials/modules/beginner/scripting

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

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;
 }
Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image dodongoo · Apr 28, 2014 at 03:46 PM 0
Share

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;
         }
avatar image The-W.A.T.Z.R · Apr 28, 2014 at 04:43 PM 0
Share

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.

avatar image robertbu · Apr 28, 2014 at 06:25 PM 0
Share

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.

avatar image The-W.A.T.Z.R · Apr 28, 2014 at 07:34 PM 0
Share

trigger ON, will not work it is already on.

but its no problem i fix it (Y) thx

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

22 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges