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 Twitch1139 · Feb 21, 2014 at 04:48 PM · loopaddremove

Help With Add and Remove on a loop

Hi I'm pretty new to scripting, and have got pretty stuck. I'm basically trying to add and remove an object on a loop with a 4 second delay in between. Any help would be awsome. p.s Turning the render on and off wont work, as the collider is still there.

Comment
Add comment · Show 8
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 zombience · Feb 21, 2014 at 05:00 PM 2
Share

we would be happy to help you debug your code if you would post it. otherwise it's somewhat of an abstract question.

avatar image JSierraAKAMC · Feb 21, 2014 at 06:09 PM 0
Share

Turn the collider on and off too.

avatar image Twitch1139 · Feb 21, 2014 at 07:21 PM 0
Share

I'm pretty noob so i have just tried different scripts i have found, tried editing a few but no success

avatar image perchik · Feb 21, 2014 at 07:27 PM 0
Share

I'd recommend learning to write code from scratch before trying to build a game by editing existing code. Try Code Academy as it's a good resource to learn scripting.

Let me be frank, it's nearly impossible to create a game without knowing how to write and think about code. Until you know what you're doing, you're going to struggle really badly.

avatar image Xtro · Feb 21, 2014 at 08:04 PM 0
Share

Perchik,

It really annoys us to see people jump into game development with zero program$$anonymous$$g knowledge. Right?

Show more comments

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Josh707 · Feb 21, 2014 at 07:56 PM

Disabling the GameObject itself with SetActive will disable all the components on it, including the collider. You can use a float subtracted by Time.deltaTime per-frame in the Update function to behave like a timer.

 public GameObject go;
 float delay = 4.0f;
 float timer = 4.0f;
 
 void Update(){
     timer -= Time.deltaTime;
     if(timer <= 0f){
         timer = delay;
         go.SetActive(!go.activeSelf);
     }
 }

Note that you have to do this from a different object because all components will be disabled, it will not continue to execute.

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 Twitch1139 · Feb 21, 2014 at 08:28 PM 0
Share

i get this error

(6,7): error CS0116: A namespace can only contain types and namespace declarations

avatar image Twitch1139 · Feb 21, 2014 at 08:29 PM 0
Share

i know javascript better than c#

avatar image Twitch1139 · Feb 21, 2014 at 08:48 PM 0
Share

i tried to change it to javascript myself , and came out with this , i have no errors , but it dosnt seem to do anything

 var go : GameObject;
 var delay : float = 4.0;
 var timer : float = 4.0;
  
 function Update(){
 
     timer -= Time.deltaTime;
 
 if(timer <= 0){
 
     timer = delay;
     go.SetActive(go.activeSelf);
 }

}

avatar image Josh707 · Feb 23, 2014 at 01:41 AM 0
Share

The reason it doesn't work is because 'activeSelf' returns the state of the object. If it is active it returns true and vice versa. The exclamation (!) is used to invert a boolean so you can set it to the opposite of it's state. No problem though!

avatar image
0

Answer by Twitch1139 · Feb 21, 2014 at 09:50 PM

this ended up working for me , with desired result.

 var delay : float = 8.0;
 var timer : float = 8.0;
 var thePrefab : GameObject;
 
   
 function Update(){
     timer -= Time.deltaTime;
 
 if(timer <= 0){
 
     timer = delay;
     var instance : GameObject = Instantiate(thePrefab, transform.position, transform.rotation);
     Destroy(gameObject.Find("Cube1(Clone)"), 4);
 }

}

Comment
Add comment · Show 1 · 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 Twitch1139 · Feb 21, 2014 at 10:53 PM 0
Share

oh and hanks Josh707 wouldnt have got this without your code

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

Multiple Cars not working 1 Answer

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

platforme ...HELP!! POSITION ADDING 1 Answer

learning the basics(9,18): UCE0001: ';' expected. Insert a semicolon at the end. 2 Answers

Trading and cargo management data structures 0 Answers


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