- Home /
This question was
closed Aug 11, 2013 at 03:55 PM by
clunk47 for the following reason:
The question is answered, right answer was accepted
Question by
RANDOMGames · Aug 10, 2013 at 03:37 PM ·
androidjavascriptmobilechange
How do i need to change this script for mobile?
This is a script for collecting pages like in slender. The problem is that i wan't to make this for android and i don't know how to, can anybody help? (it's java script just if you don't know)
@script RequireComponent ( AudioSource )
var papers : int = 0;
var papersToWin = 5;
var distanceToPaper : float = 2.5;
public var paperPickup : AudioClip;
function Start ()
{
Screen.lockCursor = true;
}
function Update ()
{
if(Input.GetMouseButtonDown (0) || Input.GetKeyDown (KeyCode.E))
{
var ray = Camera.main.ScreenPointToRay(Vector3(Screen.width * 0.5, Screen.height * 0.5, 0.0));
var hit : RaycastHit;
if(Physics.Raycast(ray, hit, distanceToPaper))
{
if(hit.collider.gameObject.name == "Paper")
{
papers += 1; audio.PlayClipAtPoint(paperPickup, transform.position);
Destroy(hit.collider.gameObject);
}
}
}
}
function OnGUI ()
{
if(papers < papersToWin)
{
GUI.Box(Rect((Screen.width * 0.5) -60, 10, 120, 25), " " + papers.ToString() + " papers");
}
else
GUI.Box(Rect((Screen.width/2) - 100, 10, 200, 35), "All Papers Collected!");
}
Comment
I've done it for you but just for future ref, please use 10101 button to post your code :D
Best Answer
Answer by meat5000 · Aug 10, 2013 at 03:41 PM
Take out key commands and mouse events and replace with Touch Handler. Check Penelope iPhone tutorials and also check out the AngryBots demo in android build; the Joystick prefab handles touches and is worth a look.