- Home /
Player touch item?
I need a Javascript... When a player touch the cube, then scene 1 will load...
I have this found on Internet:
Application.LoadLevel ("HighScore");
But what's next? I'm pretty bad in Javascript.
Thanks
Answer by liszto · Aug 06, 2013 at 09:40 AM
You can do this :
Application.LoadLevel ("TheNameOfYourScene");
but I think you will need more than that to do what you want after this small step.
Yes, i know that line... But not what needs to happen: (
Answer by christinam · Aug 06, 2013 at 09:31 AM
Have a look at the Input class in the script reference : http://docs.unity3d.com/Documentation/ScriptReference/Input.html
Answer by Joyrider · Aug 06, 2013 at 09:54 AM
I'm more of a c# guy, so I'm not going to try to write the script but the logic would be somehting like this:
1/ Add a boxcollider to your cube
2/ Write a script with this logic in it and add it to your camera for example.
var cubeCollider : Collider;
if(Input.GetButtonDown(0)) // you should change this if you're using multi-touch
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); // also to be changed if on multitouch
RaycastHit hit;
if (Physics.Raycast(ray, out hit, 100)) // cast a ray and check if something was hit
{
if(hit.collider == cubeCollider) // if something was hit, check if collider is that of the cube
{
Application.LoadLevel(1); // Loading scene 1
}
}
}
3/ drag your cube in the cubeCollider variable exposed in the inspector
Your answer
Follow this Question
Related Questions
I need help translating Javascript to C# 0 Answers
Singletons in music script? 2 Answers
Touch Control Android Java 0 Answers
Enemy detection in the light(Javascript) 1 Answer
Simple EXP Script In Javascript 0 Answers