need help with respawn code in racing game,Respawn checkpoint script not working?
I have a respawn and checkpoint counter script. it should respawn me to the last entered checkpoint when i press "R" and the checkpointcounter should reset back to 1 once it reaches 8. neither of those are currently working?
public class XS_Waypoint : MonoBehaviour
{
[SerializeField] private Transform Spawn;
[SerializeField] private Transform Waypoint1;
[SerializeField] private Transform Waypoint2;
[SerializeField] private Transform Waypoint3;
[SerializeField] private Transform Waypoint4;
[SerializeField] private Transform Waypoint5;
[SerializeField] private Transform Waypoint6;
[SerializeField] private Transform Waypoint7;
[SerializeField] private Transform player;
public int checkpointCount = 1;
void Update()
{
if (checkpointCount == 8)
{
checkpointCount = checkpointCount - 7;
}
if (Input.GetKeyDown(KeyCode.R))
{
//if you have already coillected 2 checkpoints move to checkpoint 2
if (checkpointCount == 2)
{
player.transform.position = Waypoint2.transform.position;
}
//same as above excpet incremental numbers
else if (checkpointCount == 3)
{
player.transform.position = Waypoint3.transform.position;
}
else if (checkpointCount == 4)
{
player.transform.position = Waypoint4.transform.position;
}
else if (checkpointCount == 5)
{
player.transform.position = Waypoint5.transform.position;
}
else if (checkpointCount == 6)
{
player.transform.position = Waypoint6.transform.position;
}
else if (checkpointCount == 7)
{
player.transform.position = Waypoint7.transform.position;
}
//finish with an else because it is the last checkpoint
else
{
player.transform.position = Waypoint1.transform.position;
}
}
}
private void OnTriggerEnter(Collider other)
{
//if player enters the collider it will activate the trigger adding to the checkpoint count
Rigidbody R = player.GetComponent<Rigidbody>();
if (other.gameObject.tag == "Waypoint")
{
BoxCollider BC = other.gameObject.GetComponent<BoxCollider>();
BC.enabled = false;
checkpointCount++;
}
}
}
,I have made a very rough respawn script that will move the player to each consecutive checkpoint while also resetting after it reaches a certain point within the race. Its not resetting the checkpoint integer nor respawning when i press "R". (ps i dunno the formatting for this site)
public class XS_Waypoint : MonoBehaviour { [SerializeField] private Transform Spawn; [SerializeField] private Transform Waypoint1; [SerializeField] private Transform Waypoint2; [SerializeField] private Transform Waypoint3; [SerializeField] private Transform Waypoint4; [SerializeField] private Transform Waypoint5; [SerializeField] private Transform Waypoint6; [SerializeField] private Transform Waypoint7; [SerializeField] private Transform player; public int checkpointCount = 1;
void Update()
{
if (checkpointCount == 8)
{
checkpointCount = checkpointCount - 7;
}
if (Input.GetKeyDown(KeyCode.R))
{
//if you have already coillected 2 checkpoints move to checkpoint 2
if (checkpointCount == 2)
{
player.transform.position = Waypoint2.transform.position;
}
//same as above excpet incremental numbers
else if (checkpointCount == 3)
{
player.transform.position = Waypoint3.transform.position;
}
else if (checkpointCount == 4)
{
player.transform.position = Waypoint4.transform.position;
}
else if (checkpointCount == 5)
{
player.transform.position = Waypoint5.transform.position;
}
else if (checkpointCount == 6)
{
player.transform.position = Waypoint6.transform.position;
}
else if (checkpointCount == 7)
{
player.transform.position = Waypoint7.transform.position;
}
//finish with an else because it is the last checkpoint
else
{
player.transform.position = Waypoint1.transform.position;
}
}
}
private void OnTriggerEnter(Collider other)
{
//if player enters the collider it will activate the trigger adding to the checkpoint count
Rigidbody R = player.GetComponent<Rigidbody>();
if (other.gameObject.tag == "Waypoint")
{
BoxCollider BC = other.gameObject.GetComponent<BoxCollider>();
BC.enabled = false;
checkpointCount++;
}
}
}`
Your answer
Follow this Question
Related Questions
"Creating a Basic Platformer Game" help 0 Answers
Script is detecting input with ZERO actions 0 Answers
Do you need to have specific script types for different mobile platforms? 1 Answer
Set object from array to active only whilst a specific number is returned 2 Answers
Start() and Update() execution issue 6 Answers