Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by dextreon · Jul 10, 2016 at 05:19 PM · scripting problemspawntimes

How can I modify all gameobjects that have the same script just 1 time?

Hi everyone, im trying to work a little with some spawns. I want for a specific value on the game score to change the time spawn but JUST 1 TIME in each Spawn GameObject. It just modifies 1 GameObject.

Hope u can help me! Thanks!

 using UnityEngine;
 using System.Collections;
 
 public class EnemyManager : MonoBehaviour
 {
     public GameObject enemy;               
     private float spawnTime;           
     private Transform spawnPoints;
     public float time1;
     public float time2;
     private float timeToSpawn;
     
     void Start (){
         spawnPoints = GetComponent<Transform> ();
         SetRandomTime ();
         timeToSpawn = time1;
     }
     void FixedUpdate(){
         timeToSpawn += Time.deltaTime;
         if(timeToSpawn >= spawnTime){
             Spawn ();
             SetRandomTime ();
         }
         if(GameController.score > 0 && GameController.score % 2500 == 0){
             reduce_time();
             GameController.score+=100;
             GameController.wave++;
         }
     }
     void Spawn (){
         timeToSpawn = 0.0f;
         Instantiate (enemy, spawnPoints.position, enemy.transform.rotation);
     }
     void SetRandomTime(){
         spawnTime = Random.Range (time1, time2);
     }
     void reduce_time(){
         if(time1 > 0 && time2 > 5){
             time1 -= 0.5f;
             time2 -= 0.5f;
         }
 
     }
 }
Comment
Add comment · Show 2
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 Jessespike · Jul 11, 2016 at 06:03 PM 0
Share

Can you repeat the question, it make no sense.

You want a specific score to change an object's spawn time after it has spawned once? Am I reading that right?

 //pseudo
 if (score == specificScore)
 {
     if (hasSpawnedAlready == false && spawnTime != newSpawnTime)
     {
          spawnTime = newSpawnTime;
     }
 }

avatar image dextreon Jessespike · Jul 12, 2016 at 06:31 PM 0
Share

Sry I didnt explain it clearly. Yes u're right, but the time doesn't have to change after the first spawn. It has to change in every Spawn(There are 6) when the score % 2500 == 0. So the problem is when the condition of (score % 2500 == 0) is true it reduces to the $$anonymous$$imum value available from the condition. Because of Update() loop.

 void reduce_time(){
              if(time1 > 0 && time2 > 5){ //<--Here
                  time1 -= 0.5f;
                  time2 -= 0.5f;
              }
      
          }

So I thought If I modify the score value maybe it would work fine just 1 time per Spawn.

I did this:

 if(GameController.score > 0 && GameController.score % 2500 == 0){
              reduce_time();
              GameController.score+=100; //<-- HERE
              GameController.wave++;
          }

But it just modify 1 Spawn of 6, and I want to modify all of them, but just 1 time. For example: SpawnTime is (time1=5 and time2=10) I want to reduce both in 0.5f, It would be like (time=4.5f and time2=9.5f) In every spawn.

Thanks for help!

0 Replies

· Add your reply
  • Sort: 

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

69 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 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 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 avatar image avatar image avatar image

Related Questions

error CS1526: A new expression requires () or [] after type 1 Answer

how can I add a maximum of enemies to be generated for each wave? 0 Answers

"InvalidCastException: Specified cast is not valid. (wrapper castclass)" ERROR 0 Answers

I need help with my spawning system(SOLVED) 1 Answer

Looking for someone to help me with my project 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