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 dick · Feb 27, 2012 at 03:31 PM · errorinstantiatefpsaimlocalposition

Gun Switching Error

i am trying to make a shop script for my first person shoot game. i switch weapons buy deleting the old weapon and instantiating a new one from a prefab. the weapon is suppose to auto position it's self according to variables in it's script, those variables are used in the aim script attached to the camera witch is a parent of the gun.

the system works fine except that i get this error when i switch weapons

 transform.localPosition assign attempt for 'vzr8(Clone)' is not valid. Input localPosition is { -45.218674, -0.350000, NaN }.
 UnityEngine.Transform:set_localPosition(Vector3)
 aim:Update() (at Assets/scripts/player/gun/aim.js:33)

can any one tell me what it means and how to fix it. btw here is my shop script

 private var toggle : boolean = false;
 private var player : Transform;
 private var skin: GUIStyle;
 private var bg: Texture;
 
 var guns : Transform[];
 
 function Start(){
     player = gameObject.FindWithTag("Player").transform;
     skin = gameObject.FindWithTag("Master").GetComponent("master_gameInterface").skin;
     bg = gameObject.FindWithTag("Master").GetComponent("master_gameInterface").bg;
 }
 
 function OnGUI() {
     var dist = Vector3.Distance(player.position, transform.position);
 
     myStyle = new GUIStyle();
        myStyle.normal.textColor = Color.cyan;
        myStyle.font = skin.font;
        
     if(dist<5){
         if(Input.GetKey(KeyCode.E)){
             master_gameInterface.pause = true;
             toggle = true;
         }
         if(toggle==false)
             GUI.Label(Rect(Screen.width/2,Screen.height/2,200,200), "Press E to enter Shop", myStyle);
     }
     
     if(master_gameInterface.toggle)
         toggle = false;
     
     if(toggle){
     GUILayout.BeginArea(Rect(Screen.width/2-100,Screen.height/2-200,200,400), bg);
     GUILayout.BeginVertical();
         for(var i=0;i<guns.Length;i++){
             if(GUILayout.Button(guns[i].GetComponent("gun").name, skin)){
                 if(player.GetChild(2).GetChild(0))
                     Destroy(player.GetChild(2).GetChild(0).gameObject);
                 var me = Instantiate(guns[i], player.position, Quaternion.identity);
                 me.parent = player.GetChild(2);
                 me.localPosition = player.GetChild(2).position;
                 player.GetChild(2).GetComponent("aim").gun = me;
             }
         }
         
         GUILayout.Label("\n");
         if(GUILayout.Button("Done", skin)){
             master_gameInterface.pause = false;
             toggle = false;
         }
     GUILayout.EndVertical();
     GUILayout.EndArea();
     }
 }
 
 function deleteGun(){
     for (var child : Transform in transform) {
         child.position += Vector3.up * 10.0;
     }
 }

[Edit by Berenger : code formatting]

Comment
Add comment
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

1 Reply

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

Answer by Berenger · Feb 27, 2012 at 11:48 PM

A NaN is a result of an invalid calculation. It's happening in your player's script I guess, as it is it's transform which is the problem. The best would be to find out what is causing the NaN, but you can check float.IsNaN and change the value to a default one.

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 Berenger · Feb 28, 2012 at 12:09 AM 0
Share

Forgot to mention, don't mix up GUI (2D) with world space (3D) stuff, or Inputs. Do that in Update().

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

FPS SCRIPT ERROR PLEASE HELP 2 Answers

Help spawning an object relative to the local Z axis of an object 0 Answers

Help with firing projectiles out of turret 1 Answer

Navmesh error on instantiated navmesh agents 1 Answer

Aim to crosshair? 3 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