Refactor position reset logic
This commit is contained in:
@@ -455,7 +455,7 @@ GameObject:
|
||||
- component: {fileID: 295107913}
|
||||
m_Layer: 0
|
||||
m_Name: AI Additional
|
||||
m_TagString: Untagged
|
||||
m_TagString: Player
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
@@ -658,7 +658,7 @@ Transform:
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 295107912}
|
||||
m_LocalRotation: {x: 0, y: 0.7071068, z: 0, w: 0.7071068}
|
||||
m_LocalPosition: {x: -31.8, y: 1, z: -5.7}
|
||||
m_LocalPosition: {x: -34.96, y: 1, z: 4.01}
|
||||
m_LocalScale: {x: 2, y: 2, z: 2}
|
||||
m_Children:
|
||||
- {fileID: 2145556007}
|
||||
@@ -714,7 +714,7 @@ GameObject:
|
||||
- component: {fileID: 367746335}
|
||||
m_Layer: 0
|
||||
m_Name: Player Blue
|
||||
m_TagString: Untagged
|
||||
m_TagString: Player
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
@@ -1760,7 +1760,7 @@ GameObject:
|
||||
- component: {fileID: 708460350}
|
||||
m_Layer: 0
|
||||
m_Name: Player Red
|
||||
m_TagString: Untagged
|
||||
m_TagString: Player
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
@@ -1988,7 +1988,7 @@ GameObject:
|
||||
- component: {fileID: 929235632}
|
||||
m_Layer: 0
|
||||
m_Name: Player Additional
|
||||
m_TagString: Untagged
|
||||
m_TagString: Player
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
@@ -2055,7 +2055,7 @@ Transform:
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 929235626}
|
||||
m_LocalRotation: {x: 0, y: -0.7071068, z: 0, w: 0.7071068}
|
||||
m_LocalPosition: {x: 31, y: 1, z: 8.9}
|
||||
m_LocalPosition: {x: 35.02, y: 1, z: 3.8}
|
||||
m_LocalScale: {x: 2, y: 2, z: 2}
|
||||
m_Children:
|
||||
- {fileID: 966074800}
|
||||
@@ -2576,6 +2576,9 @@ MonoBehaviour:
|
||||
player1Initial: {fileID: 0}
|
||||
player2Initial: {fileID: 0}
|
||||
ballInitial: {fileID: 0}
|
||||
players: []
|
||||
initialPositions: []
|
||||
initialRotations: []
|
||||
scoreLabel: {fileID: 697913066}
|
||||
winLabel: {fileID: 1880081387}
|
||||
--- !u!4 &1228665502
|
||||
|
||||
@@ -19,6 +19,10 @@ public class GameManager : MonoBehaviour
|
||||
|
||||
public Transform player1Initial, player2Initial, ballInitial;
|
||||
|
||||
public GameObject[] players;
|
||||
public Vector3[] initialPositions;
|
||||
public Quaternion[] initialRotations;
|
||||
|
||||
/* UI */
|
||||
public Text scoreLabel;
|
||||
public Text winLabel;
|
||||
@@ -27,6 +31,15 @@ public class GameManager : MonoBehaviour
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
this.players = GameObject.FindGameObjectsWithTag("Player");
|
||||
this.initialPositions = new Vector3[this.players.Length];
|
||||
this.initialRotations = new Quaternion[this.players.Length];
|
||||
|
||||
for (int i = 0; i < this.players.Length; i++)
|
||||
{
|
||||
this.initialPositions[i] = this.players[i].transform.position;
|
||||
this.initialRotations[i] = this.players[i].transform.rotation;
|
||||
}
|
||||
this.audioSource = GetComponent<AudioSource>();
|
||||
this.player1Initial = new GameObject().transform;
|
||||
this.player1Initial.position = this.player1.position;
|
||||
@@ -78,15 +91,16 @@ public class GameManager : MonoBehaviour
|
||||
this.audioSource.clip = this.goalSound;
|
||||
this.audioSource.Play();
|
||||
|
||||
this.player1.position = this.player1Initial.position;
|
||||
this.player1.rotation = this.player1Initial.rotation;
|
||||
this.player1.GetComponent<Rigidbody>().velocity = Vector3.zero;
|
||||
|
||||
this.player2.position = this.player2Initial.position;
|
||||
this.player2.rotation = this.player2Initial.rotation;
|
||||
this.player2.GetComponent<Rigidbody>().velocity = Vector3.zero;
|
||||
for (int i = 0; i < this.players.Length; i++)
|
||||
{
|
||||
this.players[i].transform.position = this.initialPositions[i];
|
||||
this.players[i].transform.rotation = this.initialRotations[i];
|
||||
this.players[i].GetComponent<Rigidbody>().velocity = Vector3.zero;
|
||||
}
|
||||
|
||||
this.ball.position = this.ballInitial.position;
|
||||
this.ball.GetComponent<Rigidbody>().velocity = Vector3.zero;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user