- Home /
Question by
Abdulraahman · Aug 03, 2017 at 06:08 PM ·
collisioncolliderdisableenablebox collider
keep collider disabled even when the player re-enter the scene
Hi all, I'm making a tutorials for my game and i made a script which show a picture when player enters the trigger and disable box collider when player exits but when i reenter the scene the box collider becomes enabled. Any ideas to keep it disabled even when the player re-enter the scene?
Here is the script:
#pragma strict
private var show : boolean = false;
var Text : Texture2D;
function OnTriggerEnter (other : Collider) {
if(other.gameObject.tag == "Player" && other.GetComponent(Status).level >= 1 ){
show = true;
}
}
function OnTriggerExit (other : Collider) {
if (other.gameObject.tag == "Player") {
show = false;
GetComponent.<Collider>().enabled = false;
}
}
function OnGUI () {
GUI.skin.label.normal.textColor = Color.white;
GUI.skin.label.fontSize = Screen.width/60;
if(show){
GUI.DrawTexture (new Rect (0, 0, Screen.width, Screen.height), Text, ScaleMode.StretchToFill);
if (GUI.Button (Rect (Screen.width/3-Screen.height*.25/*half width*/, Screen.height/1-Screen.height*.100/*half height*/, Screen.height*.17, Screen.height*.07), "OK")) {
show = false;
GetComponent.<Collider>().enabled = false;
}
}
}
Comment
Best Answer
Answer by ShadyProductions · Aug 03, 2017 at 07:31 PM
save it to playerprefs
PlayerPrefs.SetInt("colEnabled", 1); // 1 true 0 is false
when u enter the scene u set your collider based on your colEnabled pref in Start()
PlayerPrefs.GetInt("colEnabled") == 1 ? enabled = true : enabled = false;
Modify this pseudo code to fit your code.