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 dendens2 · Jan 21, 2013 at 05:09 AM · javascriptinspectorunity 4

Unity is not updating my script/variables

**So I added two variables and two lines of code to my script, and now it does not update it in the inspector or when I run the game. Can someone please help. I feel like I am missing something or added something extra in my script. The two variables are the recoilX and Y. And the two lines are the ones that increase the rotationX and Y by a random number 5. Help! Thanks!*

 #pragma strict
 
 //Variables
 var recoilX: float = 10;
 var recoilY: float = 10;
 var rotationSpeed: float = 0.03;
 var holdHeight: float = -0.23;
 var holdSide: float = 0.27;
 var holdDistance: float = 0.52;
 var cameraObject: GameObject;
 var ratioHipToHold: float = 1;
 var hipToAimSpeed: float = 0.1;
 @HideInInspector
 var ratioHipToHoldV: float;
 @HideInInspector
 var rotationTargetX: float;
 @HideInInspector
 var rotationTargetY: float;
 @HideInInspector
 var rotationTargetXVelocity: float;
 @HideInInspector
 var rotationTargetYVelocity: float;
 
 var walkScript: PlayerMovementScript;
 var aimingSensitivityGS: float = 0.25;
 var aimingWalkSpeedGS: float = 0.5;
 var aimFOV: float = 1;
 @HideInInspector
 var aimFOVV: float;
 @HideInInspector
 var currentFOV: float = 60;
 var defaultFOV:float = 60;
 @HideInInspector
 var positionTargetVelocity: Vector3;
 var positionMoveSpeed: float = .1;
 var rateOfFire: float = 18;
 @HideInInspector
 var fireDelay: float = 0;
 var bullet: GameObject;
 var bulletSpawn: GameObject;
 var ammo: int = 15;
 var spreadHipFire: float = 5;
 var spreadIronSight: float = 3;
 
 
 function Start () {
 
 }
 
 function Update () 
 {
     
     currentFOV = camera.main.fieldOfView;
     
     //Spawns the bullet
     if(Input.GetButtonDown("Fire1"))
     {
         if(fireDelay <= 0 && ammo > 0)
         {
             if (bullet)
             {
                 Instantiate(bullet,bulletSpawn.transform.position, bulletSpawn.transform.rotation);
                 fireDelay = 1;  
                 cameraObject.GetComponent(MouseLookScript).rotationX += (Random.value * 5);
                 cameraObject.GetComponent(MouseLookScript).rotationY += (Random.value * 5);
                 rotationTargetY +=(Random.value - 0.5) * Mathf.Lerp(spreadIronSight, spreadHipFire, ratioHipToHold);
                 rotationTargetX +=(Random.value - 0.5) * Mathf.Lerp(spreadIronSight, spreadHipFire, ratioHipToHold);
                 ammo -= 1;
             }
         }
     }
     
     
     //Reloads the weapon
     if(Input.GetButtonDown("Reload"))
     {
         ammo = 15;
     }
     
     fireDelay -= Time.deltaTime * rateOfFire;
     
     //Enables/disables iron sights. Also changes look sensitivity and walk speed
     if(Input.GetButton("Fire2"))
     {
         ratioHipToHold = Mathf.SmoothDamp(ratioHipToHold, 0, ratioHipToHoldV, hipToAimSpeed);
         cameraObject.GetComponent(MouseLookScript).aimingSensitivity = aimingSensitivityGS;
         walkScript.aimingWalkSpeed = aimingWalkSpeedGS;
         camera.main.fieldOfView = Mathf.SmoothDamp(currentFOV, aimFOV, aimFOVV, hipToAimSpeed);
     }
     else
     {
         ratioHipToHold = Mathf.SmoothDamp(ratioHipToHold, 1, ratioHipToHoldV, hipToAimSpeed);
         lookScript.aimingSensitivity = 1;
         walkScript.aimingWalkSpeed = 1;
         if(currentFOV != defaultFOV)
         {
         camera.main.fieldOfView = Mathf.SmoothDamp(currentFOV, defaultFOV, aimFOVV, hipToAimSpeed);
         }
     }
     
     //Sets position
     transform.position = cameraObject.transform.position + (Quaternion.Euler(rotationTargetX,rotationTargetY,0) * Vector3(holdSide * ratioHipToHold, holdHeight *ratioHipToHold, holdDistance));
     
     //Rotates the gun with the camera
     rotationTargetX = Mathf.SmoothDamp(rotationTargetX, cameraObject.GetComponent(MouseLookScript).rotationX, rotationTargetXVelocity, rotationSpeed);
     rotationTargetY = Mathf.SmoothDamp(rotationTargetY, cameraObject.GetComponent(MouseLookScript).rotationY, rotationTargetYVelocity, rotationSpeed);
     transform.rotation = Quaternion.Euler(rotationTargetX * -1, rotationTargetY - 180, 0);
 }
 
 //transform.position = cameraObject.transform.position + (Quaternion.Euler(rotationTargetX,rotationTargetY,0) * Vector3(holdSide * ratioHipToHold, holdHeight *ratioHipToHold, holdDistance));
     
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 iwaldrop · Jan 21, 2013 at 05:51 AM 0
Share

I don't see anything immediately apparent, but the behavior you describe seems like it should be accompanied by a console error message...is there one?

avatar image AlucardJay · Jan 21, 2013 at 05:59 AM 0
Share

If you change the values of the variables in the script, the Inspector won't show these updates. When you click on the gear icon next to the script name in the inspector, there is an option to Reset (also Remove Component, Edit Script) settings to the script. Be Aware that any prefabs or other variables you have set (dragged and dropped) in the inspector will be removed (reset to the script default, usually none without GetComponent running at Start).

avatar image dendens2 · Jan 21, 2013 at 06:23 AM 0
Share

Nope, didn't help. The inspector still contains variables that I removed. This happened after I put those two lines of code but forgot the semi-colons. When I put them in, it did not update/work. And no, there is no console error.

1 Reply

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

Answer by AndyMartin458 · Jan 21, 2013 at 06:31 AM

have you looked at what Random.value is being returned? Typically you want to use a modulus operator to put it in a certain range. Like Random.value % 360 would always return a value in the range [0,359]. Also have you made sure to save and rebuild your project? Try removing the component and adding it again.

Comment
Add comment · Show 5 · 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 dendens2 · Jan 21, 2013 at 06:36 AM 0
Share

Thanks, all I had to do was rebuild. But why do I have to rebuild sometimes and sometimes I don't?

avatar image AndyMartin458 · Jan 21, 2013 at 07:33 AM 0
Share

If you save your project, then when you go back to Unity, it will build the project for you. I wouldn't expect that you had to rebuild, but rather just that you had save and build. It's usually best to build in mono develop so thay you can look for errors and warnings. $$anonymous$$ost of the time you just need to build. Sometimes though, code is weird and the way it gets compiled can cause weird errors. Hitting rebuild is a good idea when things aren't working as expected.

avatar image Bunny83 · Jan 21, 2013 at 08:21 AM 0
Share

Uhm, this answer don't really answers the question beside the fact that it's wrong ;) Random.value will return a float value betwee 0.0f and 1.0f. If you want a specifc range, use Random.Range

avatar image dendens2 · Jan 21, 2013 at 06:45 PM 0
Share

Yea, I figured that out, but the problem was that I had to build it again.

avatar image AndyMartin458 · Jan 21, 2013 at 07:18 PM 0
Share

@Bunny83 Yes, you're probably right about Random, but all of my information was correct. So I don't know what you mean that I'm wrong. I just said to look at what is being returned to make sure that it is what is expected. $$anonymous$$y intention was to give a checklist which did work to help solve the problem.

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

13 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

Related Questions

How do i apply animations in javascript? 0 Answers

UnityScript equivalent of JavaScript objects 2 Answers

Javascript and C#, different behaviour in inspector ? 1 Answer

Enemy following Player in range 2 Answers

How to pass function as parameter to function? 1 Answer


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