- Home /
Creating a level switch by using mouse function in a certain area
Okay I'm trying to make a level change using the default FPS controller and I want to create what is essentially a button to change level. I would like to do this by using the mouse instead of the E key. and it needs to be in a cirtain area
The box selected is currently a collider but I'm not sure if it can only be a trigger. at the moment I have this
var levelSelect : String;
function OnCollisionEnter(theCollision : Collision){
if(theCollision.gameObject.name == "FPS Level End"){
Debug.Log("Hit Door");
}
}
I know I haven't got the Application.LoadLevel in there yet I just want to make sure I can get the debug working first.
Many thanks
Answer by twoc46 · Aug 26, 2012 at 07:21 PM
@Khada Thanks for the help unfortunately I'm still finding problems
I'm very new to ray casting so this so I had to look up more stuff about it (One reason why this response has taken a long time)
So far the Ray script on the object looks like this function Update () {
var up = transform.TransformDirection(Vector3.up);
var hit : RaycastHit;
Debug.DrawRay(transform.position, -up * 2, Color.green);
if(Physics.Raycast(transform.position, -up, hit, 2)){
Debug.Log("Hit");
}
}
and the Script on the controller looks like this
if(Input.GetMouseButtonDown(0))
{
Ray kRay = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit kHitInfo;
if(Physics.Raycast(kRay, out kHitInfo))
{
ScriptType kTemp = kHitInfo.collider.gameObject.GetComponent<ScriptType>();
if(kTemp != null)
{
kTemp.LoadNewScene(Level Menu);
}
}
any help will be great.