Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by psych881 · Sep 14, 2013 at 09:36 AM · androidjavascripterrorbuildcompiler

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;
             }
         }
 }
 //*****************************************************
Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image vexe · Sep 14, 2013 at 09:37 AM 0
Share

Which line is line 11?

avatar image Supershandy · Sep 14, 2013 at 09:39 AM 0
Share

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

avatar image psych881 · Sep 14, 2013 at 09:47 AM 0
Share

i found the Touch.position thing but how do i incorporate this into the code?

1 Reply

· Add your reply
  • Sort: 
avatar image
0

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))
Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image psych881 · Sep 14, 2013 at 09:54 AM 0
Share

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)'.

avatar image vexe · Sep 14, 2013 at 09:55 AM 0
Share

ScreenPointToRay takes a Vector3, not a boolean.

avatar image RyanZimmerman87 · Sep 14, 2013 at 09:58 AM 0
Share

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

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

18 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges