- Home /
Re-disable mouse input after scene change?
I am creating a simple game: 3 scenes, 3 character controllers, 3 enemies. I have it set so that right Mouse click takes you to the next scene but you can only advance once the enemy in the scene has been destroyed. It works fine for the first target but in the second scene I can freely move on without destroying the target. It seems like there's such a simple solution but I can't quite see it. I'm using JavaScript and using Raycast to destroy my enemies. I'm quite new to Unity so sorry if I ask any follow up questions aha. Any help would be great thanks:)
RClick_Enable Script:
#pragma strict
var canClick : boolean;
function Start()
{
canClick = false;
}
function Update()
{
if(RayCast_Target.objectDestroyed)
{
canClick = true;
}
if(canClick == true)
{
if((Input.GetMouseButtonDown(1)) && (Application.loadedLevel == (2)))
{
Debug.Log("Pressed right click.");
Application.LoadLevel(3);
}
if((Input.GetMouseButtonDown(1)) && (Application.loadedLevel == (2)))
{
Debug.Log("Pressed right click.");
Application.LoadLevel(3);
}
}
}
Alright, edit your post and copy/paste your code that you're using so we can see whats going on too
What i'm thinking is maybe adding something that sets canclick back to false after the new scene has been loaded.
Answer by oliver-jones · Sep 24, 2013 at 04:33 PM
Well, looking at your script. You are checking to see if 'RayCast_Target.objectDestroyed', which I'm guessing gets called when you have killed an enemy, which means that as soon as you kill your first one, it will turn 'canClick' to true... Which you only want when you have killed all 3, right?
var maxEnemy : int = 3;
var killedEnemy : int = 0;
function Update()
{
if(RayCast_Target.objectDestroyed)
{
killedEnemy ++;
}
if(killedEnemy == maxEnemy){
{
canClick = true;
}
The only issue here might be that the killedEnemy might increase every frame. I don't know how that 'RayCast_Target' is called.
Answer by SamualMeh · Sep 24, 2013 at 04:38 PM
Ahh sorted it! I needed to add a
canClick = false; RayCast_Target.objectDestroyed = false;
to both of the
if((Input.GetMouseButtonDown(1)) && (Application.loadedLevel == (2))) {
and
if((Input.GetMouseButtonDown(1)) && (Application.loadedLevel == (3))) {
Your answer
Follow this Question
Related Questions
Disable, Enable a User Input? 1 Answer
How to get GameObject that is clicked by a mouse? 2 Answers
Projection to mouse position in isometric game 1 Answer
Switch Between Touch And Mouse Controls 0 Answers
Scene Change Collision 2 Answers