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 Shujahat-Murtaza · Nov 03, 2016 at 12:49 AM · collisiondestroydamageracing

Help with Destory a vechicle code.

Hi . Developers , i am new to unity working on racing game with weapon . i have an issue on which i get stuck . I spawn a bunch of vehicles through loop , i want to destroy single vehicle if health is <=0

i spawn vehicles using this code

 public void SpawnVehicles(int vehicle){
         GameObject playercar;
         GameObject opponentrcar;
         gameTime = readyTime;
         readyTimer = true;
         countDown = true;
         spawnPoints[0].SetActive (false);

         playercar = Instantiate(playableVehicles.vehicles[raceData.vehicleNumber], spawnPoints[0].transform.position, spawnPoints[0].transform.rotation) as GameObject;

         playercar.transform.rotation = spawnPoints[0].transform.rotation;
         playercar.GetComponent<UnityStandardAssets.Vehicles.Car.CarUserControl>().enabled = false;
         racerInfo [0].racer = playercar;
         racerInfo[0].racer.name = racerInfo[0].racerName;
         racerInfo [0].lap = 1;
         playerController = playercar.GetComponent<UnityStandardAssets.Vehicles.Car.CarUserControl>();
         racerInfo[0].aIHelper = racerInfo[0].racer.GetComponent<RG_AIHelper>();
         racerInfo[0].aIController = racerInfo[0].racer.GetComponent<UnityStandardAssets.Vehicles.Car.CarAIControl>();
         racerInfo [0].waypointController = racerInfo [0].racer.GetComponent<UnityStandardAssets.Utility.WaypointProgressTracker> ();
         racerInfo [0].currentWaypoint = Waypoints [0];
         Debug.Log (raceData.numberOfRacers[raceData.raceNumber]);

             for(int i = 1; i < raceData.numberOfRacers[raceData.raceNumber]; i ++){
             spawnPoints[i].SetActive (false);
             opponentrcar = Instantiate(opponentVehicles.vehicles[i - 1], spawnPoints[i].transform.position, spawnPoints[i].transform.rotation) as GameObject;
             opponentrcar.transform.rotation = spawnPoints[i].transform.rotation;
             racerInfo[i].racer = opponentrcar;
             racerInfo[i].racerName = opponentVehicles.opponentNames[i - 1];
             racerInfo[i].racer.name = racerInfo[i].racerName;
             racerInfo [0].lap = 1;
             if(racerInfo[i].racer.GetComponent<UnityStandardAssets.Utility.WaypointProgressTracker>()){
                 racerInfo[i].aIHelper = racerInfo[i].racer.GetComponent<RG_AIHelper>();
                 racerInfo[i].aIHelper.opponentNumber = i;
                 racerInfo[i].aIController = racerInfo[i].racer.GetComponent<UnityStandardAssets.Vehicles.Car.CarAIControl>();
                 racerInfo [i].waypointController = racerInfo [i].racer.GetComponent<UnityStandardAssets.Utility.WaypointProgressTracker> ();
                 racerInfo [i].positionScore = 0;
                 racerInfo [i].currentWaypoint = Waypoints [0];
             }
         }
         opponentrcar = null;
         for (int i = 0; i < spawnPoints.Length; i++) {
             spawnPoints [i].SetActive (false);
         }
     }

i want to destroy vehicle using java code

   var hitACounter1 : int = 100;
   var Target1:GameObject;
   var destroyedcar:GameObject; 
 
   function Update () {
       if(hitACounter1<=0){
               Destroy(Target1.gameObject);
               Instantiate(destroyedcar,Target1.transform.position,Target1.transform.rotation);
           }
       }
 
   function OnTriggerEnter (hit : Collider) {
     if(hit.gameObject.tag =="Bullet" || "Bomb"){
         hitACounter1--;
     }
 }

This is my graduation project kindly guide me solution or any other good way to do that . Only thing left in my project is damage system .

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
0

Answer by bubzy · Nov 03, 2016 at 06:00 PM

put a script on the vehicle that manages the health and destroys itself when it reaches the criteria.

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 Shujahat-Murtaza · Nov 03, 2016 at 07:12 PM 0
Share

can you give me some reference??

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

101 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 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

Pass nothing inside OnTriggerEnter2D(Collider2D other) 0 Answers

how do i collide and kill the enemy while pressing space Unity 5 C# 2 Answers

Several instances destroyed when one is shot by player 0 Answers

MY effect dont destroy 0 Answers

Damage gets multiplied for some reason. 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