• 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 Shujahat-Murtaza · Nov 16, 2016 at 07:27 AM · racedie

Position Calculation after player dies

I got Stuck Help me . In game player Car has weapons . When it destroys opponent ve$$anonymous$$cle is no more position calculation using WayPionts occur . I get error of reference execption .

( MissingReferenceException: The object of type 'GameObject' has been destroyed but you are still trying to access it.Your script should either check if it is null or you should not destroy the object.)

I want that when payer is destroyed from scene it also removed from racerinfo[i] array . If anyone know how to do that plz tell me .

I am using that function for position Calculation.

void CalculateRacerPositions() { canCalculatePosition = false;

     if (Application.isPlaying && gameStarted) {
         float distance;
         for (int i = 0; i < racerInfo.Length; i ++) {
             
                 racerInfo [i].checkpointDistance = Vector3.Distance (racerInfo [i].racer.transform.position, racerInfo [i].currentWaypoint.position);
             distance = (racerInfo [i].checkpointDistance / 500);
             racerInfo [i].distanceScore = - (distance * distance);
             racerInfo [i].totalScore = racerInfo [i].positionScore + racerInfo [i].distanceScore;
             for(int i2 = 0; i2 < raceData.numberOfRacers[raceData.raceNumber]; i2++){
                 toSort[i2] = racerInfo [i2].position;
             }
             foreach (int sort in toSort.OrderBy(sorted=>sorted)) {
                 if (racerInfo [i].position == sort) {
                     managerReference.positionText [sort - 1].text = sort + "   " + racerInfo [i].racerName;
                 }
             }
         }
         for(int i2 = 0; i2 < raceData.numberOfRacers[raceData.raceNumber]; i2++){
             toSort2[i2] = racerInfo [i2].totalScore;
         }
         for (int i = 0; i < racerInfo.Length; i ++) {
             var sort2 = toSort2.OrderByDescending(sorted=>sorted).ToArray();
             float scoreCheck = racerInfo[i].totalScore;
             for (int i2 = 0; i2 < toSort2.Length; i2 ++) {
                 if (scoreCheck == sort2 [i2]) {
                     racerInfo [i].position = i2 + 1;
                 }
             }
         }
     }
     //asdad
     if(raceData.numberOfRacers[raceData.raceNumber] > 8){
         if (racerInfo [0].position > 8) {
             for (int i = 6; i < raceData.numberOfRacers[raceData.raceNumber] + 1; i++) {
                 if (racerInfo [0].position != i) {
                     managerReference.positionObject [i - 1].gameObject.SetActive (false);

                 } else {
                     Vector3 tPos;
                     tPos = managerReference.positionObject [i - 1].localPosition;
                     tPos.y = -230;
                     managerReference.positionObject [i - 1].localPosition = tPos;
                     managerReference.positionObject [i - 1].gameObject.SetActive (true);

                     tPos = managerReference.positionObject [i - 2].localPosition;
                     tPos.y = -160;
                     managerReference.positionObject [i - 2].localPosition = tPos;
                     //managerReference.positionObject [i - 2].transform.localPosition.y = -160;
                     managerReference.positionObject [i - 2].gameObject.SetActive (true);

                     tPos = managerReference.positionObject [i - 3].localPosition;
                     tPos.y = -90;
                     managerReference.positionObject [i - 3].localPosition = tPos;
                     //managerReference.positionObject [i - 2].transform.localPosition.y = -90;
                     managerReference.positionObject [i - 3].gameObject.SetActive (true);
                 }
             }
         } else {
             for(int i = 0; i < raceData.numberOfRacers[raceData.raceNumber]; i++){
                 if (i <= 7) {
                     Vector3 tPos;
                     if (i == 6) {
                         tPos = managerReference.positionObject [i].localPosition;
                         tPos.y = -160;
                         managerReference.positionObject [i].localPosition = tPos;
                     }
                     if (i == 7) {                            
                         tPos = managerReference.positionObject [i].localPosition;
                         tPos.y = -230;
                         managerReference.positionObject [i].localPosition = tPos;
                     }
                     managerReference.positionObject [i].gameObject.SetActive (true);
                 } else {
                     managerReference.positionObject [i].gameObject.SetActive (false);
                 }
             }
         }
     }
     canCalculatePosition = true;
 }

Destruction done in Health script on Opponents ve$$anonymous$$cle by calling reduceHealth(Damage)

If anyone know solution to t$$anonymous$$s problem plz help .

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 Dibbie · Nov 16, 2016 at 09:24 AM 0
Share
avatar image Shujahat-Murtaza Dibbie · Jan 18, 2017 at 07:49 AM 0
Share

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Check my race code please 3 Answers

BCE0044: expecting ), found ';'. 1 Answer

Die Function Help With C# 1 Answer

Returning to main menu 1 Answer

Race checkpoint system small help please :) 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