Quantcast
Channel: Questions in topic: "die"
Viewing all articles
Browse latest Browse all 115

Position Calculation after player dies

$
0
0
I got Stuck Help me . In game player Car has weapons . When it destroys opponent vehicle 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 vehicle by calling reduceHealth(Damage) If anyone know solution to this problem plz help .

Viewing all articles
Browse latest Browse all 115

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>