Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 dick · Aug 23, 2011 at 06:27 PM · errorraycast

ScreenPointToRay

Can someone please help. i have this gun script that uses raycasting to shoot. it worked prefectly on my other project but when i imported it to the project that iam currently developing (witch is an online muliplayer project) it sent me an error when i launched it :

NullReferenceException UnityEngine.Camera.ScreenPointToRay (Vector3 position) (at C:/BuildAgent/work/842f9557127e852/Runtime/ExportGenerated/Editor/UnityEngineCamera.cs:267) gun.Update () (at Assets/gun.js:10)

Comment
Add comment · Show 1
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 aldonaletto · Aug 23, 2011 at 06:41 PM 0
Share

You must post the script gun.js, where the error is occurring. Probably the camera variable you use with ScreenPointToView wasn't set - but we can only be sure if you show your script.

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Rennat · Aug 23, 2011 at 07:57 PM

From the limited info given in the question it seems like you forgot to set a reference in the inspector or change a property name.

It's really hard to say without seeing the script but what that error may mean is when Unity tries to run UnityEngine.Camera.ScreenPointToRay () on line 10 of your script Assets/gun.js that whatever you are passing what you think is a Vector3 object but when the code runs is null. Sometimes adding `Debug.Log()` statements near the offending line and logging the variables to see if they really are what you think they are can help in finding where the problem actually originated.

Comment
Add comment · Show 1 · 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 dick · Aug 23, 2011 at 11:53 PM 0
Share

the Input.mousePosition variable is a valide one and works in the Debug.Log() Statment. and also here is my script:

var spark : Transform;

var damage : int = 1;

var crossHairs : Texture;

var kills = 0;

private var nextFire : float = 0.0;

function Update(){

 if(networkView.is$$anonymous$$ine){

     var ray : Ray = Camera.main.ScreenPointToRay(Input.mousePosition);

     var hit : RaycastHit;

     var range = $$anonymous$$athf.Infinity;

     

     if(Input.GetButton("Fire1")){

         if(Time.time > nextFire){

             nextFire = Time.time + 0.1;

             if (Physics.Raycast (ray, hit, range)) {

                 Debug.DrawLine (ray.origin, hit.point);

                 spark.position = hit.point;

                 spark.light.enabled = true;

                 if(hit.collider.gameObject.tag == "Player"){

                     var enemyScript : health = hit.collider.gameObject.GetComponent("health");

                     enemyScript.health -= damage;

                     enemyScript.killer = this.transform;

                 }

                 spark.rotation = Quaternion.FromToRotation(Vector3.up, hit.normal);

                    spark.particleEmitter.Emit();

             }

         }

     }else{

         spark.light.enabled = false;    

     }

 }

}

function OnGUI(){

 if(networkView.is$$anonymous$$ine){

     GUI.DrawTexture(Rect(Screen.width/2 - 25,Screen.height/2 - 40,50,50),crossHairs);

     GUI.Box(Rect(Screen.width-110,Screen.height-60,100,20), "$$anonymous$$ills: " + kills);

 }

}

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

I need help with Javascript 1 Answer

RacastHit object not set to an instance of an object 1 Answer

Failed to call function Hit of class TrainingDummy 1 Answer

NullReferencException: Object reference not set to an instance of an object 1 Answer

Raycast problems unexpected token var etc. 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