- Home /
Compiler error while switching to android
I had it set to web player and had no compiller errors now that i switch to android i come up with this
NullReferenceException UnityEngine.Camera.ScreenPointToRay (Vector3 position) (at C:/BuildAgent/work/cac08d8a5e25d4cb/Runtime/ExportGenerated/Editor/UnityEngineCamera.cs:379) Paddle.Update () (at Assets/Scripts/Paddle.js:11)
My code for the Paddle.js script is
//declare the raycast objects here so we dont need to instantiate them each frame
private var ray : Ray;
private var rayCastHit : RaycastHit;
//***************************************************
function Update()
{
if(Input.GetMouseButton(0))
{
ray = Camera.main.ScreenPointToRay (Input.mousePosition);
if (Physics.Raycast (ray, rayCastHit))
{
transform.position.x = rayCastHit.point.x;
}
}
}
//*****************************************************
Your problem is that on line 11, you have it set for "mousePosition".
For an android device, this will need to be changed for a touch event where the finger touches the screen
i found the Touch.position thing but how do i incorporate this into the code?
Answer by RyanZimmerman87 · Sep 14, 2013 at 09:50 AM
if (Input.GetButtonDown ("Fire1")) {
This works for both PC mouse clicks and mobile tap screen controls.
This should work fine:
ray = Camera.main.ScreenPointToRay (Input.mousePosition);
if (Physics.Raycast (ray, rayCastHit))
You may need to add a range for the cast and add layerMask to ignore if necessary though:
if (Physics.Raycast (ray, rayCastHit, 100, layerMaskExample))
I put this from line 11
ray = Camera.main.ScreenPointToRay (Input.GetButtonDown("Fire1"));
Then I get this error now
Assets/Scripts/Paddle.js(11,52): BCE0017: The best overload for the method 'UnityEngine.Camera.ScreenPointToRay(UnityEngine.Vector3)' is not compatible with the argument list '(boolean)'.
looks like you need it like:
ray = Camera.main.ScreenPointToRay (Input.mousePosition);
if (Input.GetButtonDown("Fire1"))
{
//do code here...
if (Physics.Raycast (ray, rayCastHit, 100, layer$$anonymous$$askExample))
{
//do code here...
}
}
Edit: Gotta pass out now hope you get this working looks like your close!
Also I'm assu$$anonymous$$g you don't need the "out" in front of rayCastHit in JavaScript like you do in C#. In c# it'd be like:
if (Physics.Raycast (ray, out rayCastHit, 100, layer$$anonymous$$askExample))
I thought you didn't need that in JavaScript though but I never use it.
Your answer
Follow this Question
Related Questions
game won't work in build 0 Answers
Access JavaScript variables on c# script (Android build fails!) 1 Answer
Compiler errors while switching to android 1 Answer
Error Building Player: Extracting dlls 1 Answer
Can't build into Android 2 Answers