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 karlkevin · Mar 05, 2016 at 06:36 PM · movementtimemoving

How to speed up enemy after time?

Hello, my question is, how can i change my enemy speed, so it will get faster and faster, atm it is -8 (because it is inverted and enemy moves from up to down). For example, my 1st enemy comes with speed -8, next one already with -9 or smth, and so on. I tried InvokeRepeating, but it doesnt work the way i want to, so i commented it out atm. Thank you for your help! :)

@karlkevin

using UnityEngine; using System.Collections;

public class enemyCarMove : MonoBehaviour {

 float speed = -8f;
 // Use this for initialization
 void Start () {
     //InvokeRepeating ("speedy", 4.0f, 1.0f);
 }

 //void speedy () {
     
 //    speed = speed + -5f;

 //}

 
 // Update is called once per frame
 void Update () {
     
     transform.Translate (new Vector3(0, 1, 0) * speed * Time.deltaTime);

     }

}

Comment
Add comment
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

1 Reply

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

Answer by bubzy · Mar 05, 2016 at 09:21 PM

try

 float timeToIncrease = 1.0f; //this is the time between "speedups"
 float currentTime;  //to keep track
 float speed = 0f; //current Speed
 float speedIncrement = 5f; //how much to increase the speed by
 
 void Start()
 {
 currentTime = Time.time + timeToIncrease;
 }
 
 void Update()
 {
 if (Time.time >= currentTime)
 {
 speed += speedIncrement;
 currentTime = Time.time + timeToIncrease;
 }
 //your movement code here
 }
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 karlkevin · Mar 06, 2016 at 08:45 AM 0
Share

Thank you for your help, but atm enemy speeds up while moving from up to down. What I wanted to make, was that the spawned enemy gets faster speed every time it spawns. Like in the app called "Don't touch the white tile"- tiles are moving faster and faster, as the score gets bigger. For example if my 1st enemy comes down with speed 5, then the next ones should be faster, like 10th comes with speed already with 15 for example. I hope you could help me with this also :).

avatar image bubzy karlkevin · Mar 06, 2016 at 11:31 PM 0
Share

ok, but for this you would be better off having a spawner script and a enemy script, so that the spawner passes the speed to the enemy as it is spawned like

 using UnityEngine;
 using System.Collections;
 
 public class enemyScript : $$anonymous$$onoBehaviour {
 
     public float speed;
     // Use this for initialization
     void Start () {
     
     }
     
     // Update is called once per frame
     void Update () {
         transform.position += new Vector3(0, speed*Time.deltaTime, 0); //or however you wish to do this
     
     }
 }
 

attach that to en enemy and

 using UnityEngine;
 using System.Collections;

 public class enemySpawner : $$anonymous$$onoBehaviour {

 float speed = 0;
 float speedIncrement = 0.5f; // or whatever
 public GameObject enemy;
 public float timeDelay = 1.0f; //for the purpose of spawning at intervals, you can use what you like :)
 public float currentTime;

 // Use this for initialization
 void Start () {
     currentTime = Time.time + timeDelay;
 }
 
 // Update is called once per frame
 void Update () {
     if (Time.time > currentTime)
     {
         GameObject tempEnemy = Instantiate(enemy, transform.position, Quaternion.identity) as GameObject;
         tempEnemy.GetComponent<enemyScript>().speed = speed;
         speed += speedIncrement;
         currentTime = Time.time + timeDelay;
     }
 }
  }

this to the spawner then assign the enemy gameobject to the spawner in the inspector.

avatar image karlkevin bubzy · Mar 09, 2016 at 08:26 AM 0
Share

THAN$$anonymous$$ YOU VERY $$anonymous$$UCH!! :) Now it almost works as i want to, thank you!!! :)

Show more comments

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

54 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

Related Questions

Stop movement on collision 1 Answer

how can i repeat an if statment for x sec? 1 Answer

Player doesn't move 0 Answers

Skid steer type movement 1 Answer

Make an Object Stop Moving Upon Collision 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