So i am trying to make a revive button which spawns you the place where you died.But in the place where you died there is an object called “Obstacle” (which killed you) so i should disable the collider of the tagged objects for 3 or 4 seconds.
//This is from my "Score" script.This function is getting called by the ReviveButton.So i should add the disabling collider code here.
public void Revive()
{
isDead = false;
deathMenu.ToggleEndMenuKapat ();
FindObjectOfType<AudioManager> ().Play ("Theme");
reviveButton.gameObject.SetActive (false);
}
//And this is from my movement script.Both scripts are seperate.
private void OnControllerColliderHit(ControllerColliderHit hit)
{
if (hit.gameObject.tag == "Obstacle")
Death ();
FindObjectOfType<AudioManager> ().Stop ("Theme");
FindObjectOfType<AudioManager> ().Play ("Death Sound");
}
You will have to make changes to both your functions.
Let’s call the script that has the OnControllerColliderHit function ScriptA and the script that has Revive function ScriptB.
In Scrip A declare a variable.
public static GameObject deathByObstacle;
Now in the function OnControllerColliderHit makes these changes.
private void OnControllerColliderHit(ControllerColliderHit hit)
{
if (hit.gameObject.tag == "Obstacle")
{
deathByObstacle = hit.gameObject;
Death ();
FindObjectOfType<AudioManager> ().Stop ("Theme");
FindObjectOfType<AudioManager> ().Play ("Death Sound");
}
}
Next is to make a function in ScriptB calledTurnOnCollider.
void TurnOnCollider()
{
ScriptA.deathByObstacle.GetComponent<Collider>().enabled=true;
}
Next, you will have to make changes to the Revive function.
public void Revive()
{
isDead = false;
deathMenu.ToggleEndMenuKapat ();
FindObjectOfType<AudioManager> ().Play ("Theme");
reviveButton.gameObject.SetActive (false);
ScriptA.deathByObstacle.GetComponent<Collider>().enabled = false
Invoke ("TurnOnCollider", 3);
}
What I’m doing is making a global reference to the game object that caused the death and when the player is revived I turn off the collider and using the Invoke function turn on the collider after 3 seconds.
If you want to learn what the Invoke function does here is the 1.
If you have any other questions let me know!