- Home /
randomized jumpscare not working!
hello ive made it so that when the player collides with the enemy, a random jumpscare occurs. The thing is, the player just collides with the enemy normally as if it was a gameobject. please help me. i got no errors.
my code:
var mainCam : Camera;
var jsCam : Camera;
var jsCamOne : Camera;
var jsCamTwo : Camera;
var overCam : Camera;
var player : GameObject;
private var Jumpscare = false;
function Update ()
if (Jumpscare = true)
{
gameOver();
}
function OnTriggerEnter (theCollider : Collider)
{
if (theCollider.tag == "Player") {
var randomnumber = Random.Range(0,3);
{
if(randomnumber == 0) {
Jumpscare = true;
jsCam == true;
jsCamOne == false;
jsCamTwo == false;
mainCam == false;
overCam == false;
gameOver();
}
if(randomnumber == 1) {
Jumpscare = true;
jsCamOne == true;
jsCamTwo == false;
jsCam == false;
overCam == false;
mainCam == false;
gameOver();
}
if(randomnumber == 2) {
Jumpscare = true;
jsCamTwo == true;
jsCamOne == false;
overCam == false;
jsCam == false;
mainCam == false;
gameOver();
}
}
}
function gameOver ()
{
yield WaitForSeconds(1);
jsCam == false;
jsCamTwo == false;
jsCamOne == false;
overCam == true;
mainCam == false;
}
problem 1. Line 10. You are using assignment operator = ins$$anonymous$$d of equality operator ==.
jsCam == false just compares the values and returns true or false.
If you want to enable/disable cameras use jsCam.enabled = true/false;
== is for comparison = is for assigning a value
problem 2. You are calling gameover function from both Update and OnTriggerEnter. Do you want game over to be called more than once per collision?
problem 3 (well actually still problem 1) You are using == all over where you should be using =.
problem 4. If you are setting some variable to the same value in all three if-cases (like Jumpscare, overCam, mainCam), you might as well write it down outside of that if's. Do not repeat your code all over.
Your answer
![](https://koobas.hobune.stream/wayback/20220613181227im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Trying to Tackle ledge climbing with blender animated Character!! 0 Answers
Running Unity FREE license on school computers 1 Answer
Trying to make a score script that shows the score through a GUIText object. 0 Answers
Reference error -_- Annoyed please help 1 Answer
Collider has illegal parameters 0 Answers