- Home /
Screen go Gray and only Cursor active OnTriggerEnter
Greetings! So i have those two scripts below. One attached to my Floor and the other to my Player. Is there a way to make the screen go gray as soon as the player enter the Trigger and make only the cursor active not the whole mouselook script of the First Person Controller? I tried using Time.timeScale but only the movement was frozen. I could still look around with the mouse. Thanks!
TriggerFloor.js
var showGUI : boolean = false;
var original : Vector3;
var player : GameObject;
function Start(){
player = GameObject.Find("Player");
original = player.transform.position;
}
function OnTriggerEnter(other:Collider){
if(other.gameObject.name == "Player"){
var otherScript = player.GetComponent(FallDamage);
otherScript.hearts -= 1;
showGUI = true;
}
}
function OnGUI(){
if(showGUI){
if(GUI.Button(new Rect(20,70,100,50), "Respawn")){
player.transform.position = original;
showGUI = false;
}
}
}
FallDamage.js
var hearts : int = 3;
function OnGUI(){
GUI.Box(new Rect(20,20,100,40), "Hearts : " + hearts);
if(hearts < 0){
hearts = 0;
Destroy(this.gameObject);
}
}
Answer by ExTheSea · May 02, 2013 at 05:14 PM
So to make the screen go gray you could use something like in this answer: http://answers.unity3d.com/questions/31193/screen-flashes-red-when-taking-damage.html
and to disable the mouseLook-Script you could do somthing like this:
var theCamera : GameObject; //Assign the Camera or gameobject which has the mouselook-script attached
...
theCamera.GetComponent("MouseLook").enabled = false;
If you need to disable other scripts to make it work you can do it similar. just get the component and set its enabled state to false.
Good Luck.
ExTheSea
Ok i don't about the gray screen yet. I haven't tried it yet :P And actually i don't want to have a flash for a second or two. I want my screen to become gray and feel like the game is paused. About the $$anonymous$$ouseLook your example worked except that i still can move the camera up and down with the cursor :S What should i add?
You need to fin which script is is making the camera move up and down still because the $$anonymous$$ousLook-Script is disabled so it can't be it. When you find the script which is still making the camera move u can disable it by thegameojectitson.GetComponent("TheScript").enabled = false;
Btw. It wouldn't be an option for you to remove or disable the player/camera and then activating/instantiating another one to do the GUI stuff?
Ok i get it. I'll try to locate that other script. About the last part you wrote, hmm what i want is when my Player falls down on the floor and enters the trigger, the whole game will kind of pause and the screen will go gray and the respawn button will appear. Now that i think about it though, maybe i'll do it possible with just one button :P
What you should consider in the case you are describing, is using some kind of Image Effect (are you using Unity Pro?) when pausing, on the camera of course. And also of course pause the mouse movement just like ExTheSea has described.
No just the Free version of it. I see. Thanks a lot guys! I'll see what i can do by myself. Eventually, i'll make it happen :)
Your answer
![](https://koobas.hobune.stream/wayback/20220613101357im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Breathing sound effect using timers 1 Answer
OnTriggerEnter can't detect my Transform tag 1 Answer
Check for collision while animating 0 Answers
Help With Quickest TimeScore 0 Answers