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 /
  • Help Room /
avatar image
0
Question by sanderschellekens · Apr 17, 2016 at 12:23 PM · textissueuser interfacespeedometer

CS0122 C# is inaccessible due to its protection level when accessing PlayerController.rb......

Hey guys, i'm trying to make a simple speed/velocity meter, I found out i could do so by accesing the rigidbody's velocity.magnitude. Only problem is, the rigidbody belongs to the player gameobject rather than the textUI object.

 using UnityEngine;
 using UnityEngine.UI;
 using System.Collections;
 
 public class Speedmeter : MonoBehaviour
 {
     public float Speed;
     public GameObject CuboidPlayer;
     public Rigidbody rb;
 
 
     public Text text;
 
     void Awake()
     {
         text = GetComponent<Text>();
     }
 
     void Start()
     {
         GameObject.Find("CuboidPlayer");
         Speed  = PlayerController.rb.velocity.magnitude;
 
     }
 
     void Update()
     {
 
         text.text = " " + PlayerController.rb.velocity.magnitude;
     }
 }
 

It presents me with said error and an unworking project with this playercontroller script: ( unworking as in nothing responds anymore while there are no errors or whatsoever except the one mentioned ).

 using UnityEngine;
 using System.Collections;
 
 [System.Serializable]//This adds another class to the script menu in the inspector tab.
 public class Boundary
 {
     public float xMin, xMax, yMin, yMax, zMin, zMax;
 }
 
 
 public class PlayerController : MonoBehaviour
 
 {
     public GameObject attractedTo;// Set's gravity pull towards star
     public float strengthOfAttraction = 5.0f;
 
     //The purpose of this script is to simulate Newtonian phy
     public float maxThrust = 0.01f; //The maximum Thrust provided by the thruster(s) at full throttle
     public float rollWeight = 0.000000000005f; //This float and the next two only serve to adjust sensitivity
     public float pitchWeight = 0.000000000005f;//of the controls, and to allow calibration for more massive ships.
     public float yawWeight = 0.00000000005f;//Set these 3 floats to the mass of the rigidbody for sensitive controls
     public AudioClip ImpulseSound;
     public Boundary boundary;
     public float speed;
 
     private bool isMoving;
     bool isPlaying;
 
     Rigidbody rb;
    
     void Start()
     {
         rb = GetComponent<Rigidbody>();
         isMoving = (Input.GetKeyDown("z") || Input.GetKeyDown("x") || Input.GetKeyDown("left") || Input.GetKeyDown("right") || Input.GetKeyDown("up") || Input.GetKeyDown("down"));
 
         
 
     }
 
     void Update()
     {
         speed = rb.velocity.magnitude;
         //The code below describes when to play the sound to tell you are moving.
 
         if (isMoving)
         {
             GetComponent<AudioSource>().clip = ImpulseSound;
             GetComponent<AudioSource>().Play();
         }
 
         else
         {
             GetComponent<AudioSource>().clip = ImpulseSound;
             GetComponent<AudioSource>().Stop();
         }
             transform.position = new Vector3 //Here I clamp the cuboid's position within the Cubiverse sector's boundaries
             (
                 Mathf.Clamp(GetComponent<Rigidbody>().position.x, boundary.xMin, boundary.xMax),
                 Mathf.Clamp(GetComponent<Rigidbody>().position.y, boundary.yMin, boundary.yMax),
                 Mathf.Clamp(GetComponent<Rigidbody>().position.z, boundary.zMin, boundary.zMax)
                 );
     }
 
 
 
     void FixedUpdate()
     {
         Vector3 direction = attractedTo.transform.position - transform.position;//Sets values for gravity pull towards star
         GetComponent<Rigidbody>().AddForce(strengthOfAttraction * direction);
 
         float yaw = yawWeight * Input.GetAxis("Yaw") * Time.deltaTime;//Movement and rotation on 3 axis'
         float roll = rollWeight * Input.GetAxis("Roll") * Time.deltaTime;
         float pitch = pitchWeight * Input.GetAxis("Pitch") * Time.deltaTime;
         Vector3 Rotation = new Vector3(pitch, roll, yaw);
         rb.AddRelativeTorque(Rotation);
         float throttle = maxThrust * Input.GetAxis("Thrust");
         rb.AddRelativeForce(Vector3.forward * throttle);
         System.Console.WriteLine("input is " + yaw.ToString() + ", " + pitch.ToString() + ", " + roll.ToString());
 
         float strafeHor = maxThrust * Input.GetAxis("StrafeHorizontal");
         rb.AddRelativeForce(Vector3.left * strafeHor);
         float strafeVer = maxThrust * Input.GetAxis("StrafeVertical");
         rb.AddRelativeForce(Vector3.up * strafeVer);
         
             
 
         
     }
 }


after trying to make the public float speed in the PlayerController script static it all went wrong. I intentionally didn't try a static variable at first because that seemed, static rather than dynamic which i want for my ship. I want the number to go up or down a long the values presented by my cuboid's rigidbody.

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

0 Replies

· Add your reply
  • Sort: 

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Issue with instantiated text clone 0 Answers

Prevent escape key from deleting InputField contents, have it save instead? 4 Answers

Combine text and buttons in scroll rect 0 Answers

UI and GUI not updating score? 1 Answer

Dialogue not displaying next sentence 0 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