- public GameObject[] spawnPoints;
- void OnCollisionEnter(Collision collision) {
- if (collision.collider.tag == "Respawn"){
- ArrayList respawnList = RespawnAtNearestPoint(transform.position);
- Vector3 respawnSpot = (Vector3) respawnList[0];
- transform.position = respawnSpot;
- Quaternion respawnRotation = (Quaternion) respawnList[1];
- transform.rotation = respawnRotation;
- rigidbody.velocity = Vector3.zero;
- rigidbody.angularVelocity = Vector3.zero;
- }
- }
- ArrayList RespawnAtNearestPoint(Vector3 curPos){
- ArrayList respawnList = new ArrayList();
- Transform closestPoint = spawnPoints[0].transform;
- float shortestDistance = Vector3.Distance(curPos, closestPoint.position);
- foreach(GameObject point in spawnPoints){
- float curDist = Vector3.Distance(curPos, point.transform.position);
- if(shortestDistance > curDist){
- shortestDistance = curDist;
- closestPoint = point.transform;
- }
- }
- respawnList.Add(closestPoint.position);
- respawnList.Add(closestPoint.rotation);
- return respawnList;
Tuesday, 30 April 2013
spawn point script and tutiorial
Labels:
jesse
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment