- Home /
Question by
nils.hamlin · Jan 26, 2013 at 01:39 PM ·
javascriptraycastrandomloadwrong
raycast to object, load wrong script!?
When pressing object to load level, it loads wrong level and randomly. Same script at all 3 balls. only loadlevel different. Why does it load wrong level?
I also added the project, its 287kb.
function Update ()
{
if (Input.GetMouseButtonDown(0))
{
var hit : RaycastHit;
var ray : Ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, hit))
{
Application.LoadLevel ("Blue");
}
}
}
[1]: /storage/temp/7175-testproject_delete.zip
example.png
(60.7 kB)
testproject_delete.zip
(293.7 kB)
Comment
Answer by whydoidoit · Jan 26, 2013 at 01:40 PM
Because all three scripts say if anything is hit then load - whichever one gets to go first loads the level
You are probably looking for
function OnMouseDown()
{
Application.LoadLevel("Blue");
}
Or preferably:
var levelToLoad : string;
function OnMouseDown()
{
Application.LoadLevel(levelToLoad);//Set this in the inspector
}
Answer by nils.hamlin · Jan 31, 2013 at 07:23 PM
thank you very much, make sence now when you say it and easier script! :-)