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 damneasy · Dec 16, 2015 at 02:19 PM · scripting problemtags

How do i add my objects to a tag

I've made this "frogger" game with 8 cars, but i want to have an "up" and a "down" tag so i dont have to make a startcar1-100 for every car. I already made the tags but i dont know how to add the objects to the tag

 using UnityEngine;
 using System.Collections;
 
 public class scriptCar : MonoBehaviour {
 
     public GameObject up, down, startCar1, startCar2, startCar3, startCar4, startCar5, startCar6, startCar7, startCar8;
     public float speed1, speed2, speed3, speed4, speed5, speed6, speed7, speed8;
     public int score;
 
     // Use this for initialization
     void Start () {
 
     }
     
     // Update is called once per frame
     void Update () {
         
         speed1 = Random.Range (5, 10);
         speed2 = Random.Range (7, 12);
         speed3 = Random.Range (1, 6);
         speed4 = Random.Range (9, 14);
         speed5 = Random.Range (4, 9);
         speed6 = Random.Range (6, 1);
         speed7 = Random.Range (7, 12);
         speed8 = Random.Range (3, 9);
 
         startCar1.transform.Translate (0, -speed2 * Time.deltaTime, 0);    
         if (startCar1.transform.position.y < -9){
             startCar1.transform.position = new Vector3 (-2.3F, 8, 0);
             
         }
 
         startCar2.transform.Translate (0, -speed2 * Time.deltaTime, 0);        
         if (startCar2.transform.position.y < -9){
             startCar2.transform.position = new Vector3 (-1.65F, 8, 0);
         }
 
         startCar3.transform.Translate (0, -speed3 * Time.deltaTime, 0);        
         if (startCar3.transform.position.y < -9){
             startCar3.transform.position = new Vector3 (-1.05F, 8, 0);
         }
 
         startCar4.transform.Translate (0, -speed4 * Time.deltaTime, 0);        
         if (startCar4.transform.position.y < -9){
             startCar4.transform.position = new Vector3 (-0.35F, 8, 0);
         }
 
         startCar5.transform.Translate (0, speed5 * Time.deltaTime, 0);        
         if (startCar5.transform.position.y > 9){
             startCar5.transform.position = new Vector3 (0.35F, -8, 0);
         }
 
         startCar6.transform.Translate (0, speed6 * Time.deltaTime, 0);        
         if (startCar6.transform.position.y > 9){
             startCar6.transform.position = new Vector3 (1F, -8, 0);
         }
 
         startCar7.transform.Translate (0, speed7 * Time.deltaTime, 0);        
         if (startCar7.transform.position.y > 9){
             startCar7.transform.position = new Vector3 (1.65F, -8, 0);
         }
 
         startCar8.transform.Translate (0, speed8 * Time.deltaTime, 0);        
         if (startCar8.transform.position.y > 9){
             startCar8.transform.position = new Vector3 (2.25F, -8, 0);
         }
         
     }
 }
 

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 Soraphis · Dec 16, 2015 at 08:41 PM 0
Share

you should not do it like this. ever.

use an array and loops, you should look into $$anonymous$$athf.Repeat(). and the script should not handle each car, ins$$anonymous$$d each car should use this script, and the script should work for each car

btw: error in line 27 you never use speed1

avatar image damneasy Soraphis · Dec 16, 2015 at 10:45 PM 0
Share

But that cant work because i have 8 lines of road, each car has to go on a differnt road, if i make the script for all cars all cars would go on the same road?

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Jessespike · Dec 16, 2015 at 07:52 PM

 public GameObject startCar1;

 void Start() {
     startCar1.tag = "Put_Tag_Name_Here";
 }
Comment
Add comment · 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

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

How to compare audio sequences in unity 0 Answers

tagged objects problem 0 Answers

Multiple Tags with FindGameObjectsWithTag...? 1 Answer

Why ain't this working? 1 Answer

I want to do a pause panel 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