Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 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 VisLock · Aug 13, 2015 at 09:03 AM · speed

speed diffrence

This code is connected to for game-objects but for some reason all of the game-objects get different speeds and they all started with the same speed.(the tags are set correctly)

using UnityEngine; using System.Collections;

public class Arrow : MonoBehaviour {

 public GameObject target;
 public GameObject target1;
 public GameObject target2;
 public GameObject target3;
 public GameObject target4;
 public GameObject target5;
 public GameObject target6;
 public GameObject target7;



 private int speed = 5;

 private int ranN;



 void Update () {
     transform.position += Vector3.back * speed * Time.deltaTime;
 
 }







 void OnTriggerEnter (Collider other) {
 
     if (other.gameObject.CompareTag ("reset")) {
     
         ranN = Random.Range (1, 8);
     
     }
     if (ranN == 1) {
         transform.position = target.transform.position;
         speed = speed + 1;
     } else {
         if (ranN == 2) {
             transform.position = target1.transform.position;
             speed = speed + 1;
         } else {
             if (ranN == 3) {
                 transform.position = target2.transform.position;
                 speed = speed + 1;
             } else {
                 if (ranN == 4) {
                     transform.position = target3.transform.position;
                     speed = speed + 1;
                 } else {
                     if (ranN == 5) {
                         transform.position = target4.transform.position;
                         speed = speed + 1;
                     } else {
                         if (ranN == 6) {
                             transform.position = target5.transform.position;
                             speed = speed + 1;
                         } else {
                             if (ranN == 7) {
                                 transform.position = target6.transform.position;
                                 speed = speed + 1;
                             }
                         }
                     }
                 }
             }
         }
     }
     

 }
 }
Comment
Add comment · Show 3
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 stepan-stulov · Aug 13, 2015 at 09:29 AM 1
Share

I see a narrative but no question. UnityAnswers implies a question to be asked first.

avatar image Nabeel Akhtar · Aug 13, 2015 at 09:32 AM 0
Share

As u are increasing speed on onTriggerEnter the more a object hit it gets more speed. And speed is private variable so all will start with same speed value of 5 and changing speed when hitting some other collider individually. In this code u r not assigning velocity, U r changing its position. Assign Velocity to rigidbody to move object if u only purpose is to move

avatar image rajavamsidhar_gvs · Aug 13, 2015 at 10:10 AM 0
Share

You are giving all with same speed thats why they are starting with same speed.but what is the final question in that.can u give more info about then anyone can give you good solution.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Problem with time !! help me 1 Answer

Rotate object from localRotation A to localRotation B at rate C. 2 Answers

Collider problems with Speed 1 Answer

How to Access AnimaionState in Mecanim? 1 Answer

Acceleration of Transform in FixedUpdate (SOLVED) 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