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 /
This question was closed Mar 01, 2015 at 04:13 AM by meat5000 for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by Koach · Feb 28, 2015 at 03:29 PM · c#inspectorpublic variable

c# public variables not appearing in inspector

Hey there, I'm just trying to make a simple script that lets a camera follow a character since parenting the camera doesn't work. For whatever reason, none of the variables appear in the editor, so naturally it runs into issues since I can't drag the character into the variable slot. Anyone know what's going on? Here's the code:

 using UnityEngine;
 using System.Collections;
 
 public class cameraTracking : MonoBehaviour {
 
     public GameObject targetl;
     public float xOffset = 0;
     public float yOffset = 0;
     public float zOffset = 0;
     
     void LateUpdate() {
         this.transform.position = new Vector3(target.transform.position.x + xOffset,
                                               target.transform.position.y + yOffset,
                                               target.transform.position.z + zOffset);
     }
 }


Comment
Add comment · Show 4
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 gjf · Feb 28, 2015 at 12:14 PM 0
Share

Please format ALL of your code

Are you getting any errors?

avatar image Mmmpies · Feb 28, 2015 at 03:32 PM 0
Share

O$$anonymous$$ I formatted your code for you as you're new but be careful to do it correctly with your next question.

Have you dragged the script onto a GameObject?

avatar image Firedan1176 · Feb 28, 2015 at 03:43 PM 0
Share

Try: Right clicking on the script in the Project tab and click reimport/refresh $$anonymous$$ake sure it's on a GameObject Do you have any editor scripts overriding it?

avatar image Haxxxxx · Feb 28, 2015 at 03:46 PM 0
Share

If you have errors in monodevelop or whatever other IDE you're using the inspector won't update itself, usually I like to comment out all code but my variables in VS in a few keys (CTRL $$anonymous$$ + C), not sure the command for doing so in $$anonymous$$onodevelop. Basically, comment out your errors and let it update in the inspector then go back to your code.

This isn't always the case but it tends to be a niggly problem that catches out even the experienced Unity users.

1 Reply

  • Sort: 
avatar image
4
Best Answer

Answer by maccabbe · Feb 28, 2015 at 05:27 PM

The reason the variables are not being displayed is because there is a compile time error in your script because LateUpdate is referring to the variable target when you only declare a variable named target1. Use the following:

 using UnityEngine;
 using System.Collections;
  
 public class cameraTracking : MonoBehaviour {
  
      public GameObject target;
      public float xOffset = 0;
      public float yOffset = 0;
      public float zOffset = 0;
      
      void LateUpdate() {
          this.transform.position = new Vector3(target.transform.position.x + xOffset,
                                                target.transform.position.y + yOffset,
                                                target.transform.position.z + zOffset);
      }
  }
Comment
Add comment · Show 2 · 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 Koach · Mar 01, 2015 at 03:51 AM 0
Share

Thanks maccabbe, that's got it working properly. To everyone else who answered, thanks for the help! And thanks for putting up with the new guy. By what do you mean formatting my code? I don't want to make the same mistake in what is likely to be a long list of other questions.

avatar image Mmmpies · Mar 01, 2015 at 09:04 AM 0
Share

You had formatted some of the code but only in places making it difficult to read, just highlight all the code and hit the 101010 button to format, seemed to be in moderation for a long time but then Answers is run by volunteers so there are only ever a few people on here able to moderate.

$$anonymous$$ake your question as easy to answer as possible and always search for answers first as it's always quicker.

That said the fact you're asking how to post correctly means you're probably a good poster, look at the FAQ or the Tutorial Video for more information.

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

Distribute terrain in zones 3 Answers

Public and SerializedField's not showing in inspector 1 Answer

How to make public variable read-only during run-time? 3 Answers

C# | public variables in parent class should not show up in child class 1 Answer

Multiple Cars not working 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