overlapping objects triggering scene change with spacebar

Hi - I am making a 2D top down game which involves characters moving around the screen and the gamer moving a crosshair with the arrow keys. Can anyone please help me work out how to trigger a scene change when the crosshair overlaps with a specific character and the spacebar is pressed. Thanks!

Maybe the simplest way would be to have a trigger/collision detected between the crosshair and the specific character. Then set a variable to say that such an occurence has taken place, and if that’s true, and the spacebar is pressed, change scenes.

Hi methos5k thanks for replying, That’s exactly what I need to do! Only thing is that I don’t know enough to write the code to do this. If at all possible, could you be more specific about what code I need to write to do this please?
Your help is very much appreciated. Thanks Milo.

Okay, there are just a few things: trigger/collision + detecting the right person/character, then there’s Key Input, and then there’s changing the scene.

In place of collision/trigger, you could use the Event system instead.

I’m happy to help more, but it would be good if you looked into these areas, and tried to learn & write something yourself.
Then, you can come back with what you have & say if you got it and/or what happened and show what you’ve tried… and we can work through it. Okay? :slight_smile:

Thanks so much. Sound great, I’ll give it a go and get back to you.

Sure, sounds good…

Hi, so far I’ve figured out how to change scene using application.loadLevel and I know how how to get key inputs using Input.GetKey. I also know that the collision involves raycasters. I still don’t know how to specify the person that the cross hair needs to overlap with. I have had exams this week so I have had limited time to work on this unfortunately. the big problem is that I am meant to be demoing this game tomorrow! I have written these lines of code from what I’ve learnt. Please could help me with my mistakes and the gaps in my knowledge. Thank you.

//this is the bit i don’t know
if (Input.GetKey (KeyCode.Space), overlap with civ 4)
{
Application.LoadLevel (“Menu”);
}

Where is the Raycasting or trigger that you tried ?

Hi, just in case you get to this, here is an update on my code. I should work but I don’t know why it isn’t.

public Transform Cube, Cube1;

public bool spotted = false;

void Update()
{

Raycasting();

if (spotted == true) {

Application.LoadLevel (“Menu”);
}

}

void Raycasting()
{
Debug.DrawLine(Cube1.position, Cube.position, Color.green);
spotted = Physics2D.Linecast (Cube1.position, Cube.position);
}