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 /
This question was closed Jan 22, 2018 at 04:38 PM by meat5000 for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by Vampyr_Engel · Feb 27, 2016 at 07:16 PM · c#classstructinvalidtoken

Invalid token 'in' class, struct, or interface member declaration Problem

Hello I am having a problem since changing an old command (Rigidbody.rigidbody) for a new updated one( UnityEngine.Component.Rigidbody.rigidbody;) I am getting these Invaild Token Errors The script looks OK except for this one error I can't solve can someone please help?

 using UnityEngine;
 using System.Collections;
 
 [RequireComponent (typeof (GravityBody))]
 public class FirstPersonHoverTank : MonoBehaviour {
     
     // public vars
     public float mouseSensitivityX = 250;
     public float mouseSensitivityY = 250;
     public float hoverSpeed = 20;
     public float jumpForce = 1000f;
     public float hoverForce = 65f;
     public float hoverHeight = 3.5f;
     public LayerMask groundedMask;
     
     // System vars
     bool grounded;
     Vector3 moveAmount;
     Vector3 smoothMoveVelocity;
     float verticalLookRotation;
     Transform cameraTransform;
     UnityEngine.Component.Rigidbody.rigidbody;
     
     
     void Awake() {
         Screen.lockCursor = true;
         cameraTransform = Camera.main.transform;
         rigidbody = GetComponent<Rigidbody> ();
     }
     
     void Update() {
         
         // Look rotation:
         transform.Rotate(Vector3.up * Input.GetAxis("Mouse X") * mouseSensitivityX * Time.deltaTime);
         verticalLookRotation += Input.GetAxis("Mouse Y") * mouseSensitivityY * Time.deltaTime;
         verticalLookRotation = Mathf.Clamp(verticalLookRotation,-60,60);
         cameraTransform.localEulerAngles = Vector3.left * verticalLookRotation;
         
         // Calculate movement:
         float inputX = Input.GetAxisRaw("Horizontal");
         float inputY = Input.GetAxisRaw("Vertical");
         
         Vector3 moveDir = new Vector3(inputX,0, inputY).normalized;
         Vector3 targetMoveAmount = moveDir * walkSpeed;
         moveAmount = Vector3.SmoothDamp(moveAmount,targetMoveAmount,ref smoothMoveVelocity,.15f);
         
         // Jump
         if (Input.GetButtonDown("Jump")) {
             if (grounded) {
                 rigidbody.AddForce(transform.up * jumpForce);
             }
         }
         
         // Grounded check
         Ray ray = new Ray(transform.position, -transform.up);
         RaycastHit hit;
         
         if (Physics.Raycast(ray, out hit, 1 + .1f, groundedMask)) {
             grounded = true;
         }
         else {
             grounded = false;
         }
         
     }
     
     void FixedUpdate() {
         // Apply movement to rigidbody
         Vector3 localMove = transform.TransformDirection(moveAmount) * Time.fixedDeltaTime;
         rigidbody.MovePosition(rigidbody.position + localMove);
     }
 }

Comment
Add comment · Show 5
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 Vampyr_Engel · Feb 29, 2016 at 06:18 AM 0
Share

Oh O$$anonymous$$ thank you very much EmHuynh though getting a the type 'Ridgidbody' does not exist in the type 'UnityEngine.Component' error what am I doing wrong now?

avatar image EmHuynh Vampyr_Engel · Mar 02, 2016 at 07:54 PM 0
Share

@Vampyr_Engel, I am sorry for the delay of my response. Can you please provide the changes you made? Thanks!

avatar image Vampyr_Engel EmHuynh · Mar 02, 2016 at 10:40 PM 0
Share

O$$anonymous$$ using UnityEngine; using System.Collections;

 [RequireComponent (typeof (GravityBody))]
 public class FirstPersonHoverTank : $$anonymous$$onoBehaviour {
     
     // public vars
     public float mouseSensitivityX = 250;
     public float mouseSensitivityY = 250;
     public float hoverSpeed = 20;
     public float jumpForce = 1000f;
     public float hoverForce = 65f;
     public float hoverHeight = 3.5f;
     public Layer$$anonymous$$ask grounded$$anonymous$$ask;
 
     // System vars
     bool grounded;
     Vector3 moveAmount;
     Vector3 smooth$$anonymous$$oveVelocity;
     float verticalLookRotation;
     Transform cameraTransform;
     UnityEngine.Component.Rigidbody   rigidbody;
 
 
     
     
     void Awake() {
         Screen.lockCursor = true;
         cameraTransform = Camera.main.transform;
         rigidbody = GetComponent<Rigidbody> ();
     }
     
     void Update() {
         
         // Look rotation:
         transform.Rotate(Vector3.up * Input.GetAxis("$$anonymous$$ouse X") * mouseSensitivityX * Time.deltaTime);
         verticalLookRotation += Input.GetAxis("$$anonymous$$ouse Y") * mouseSensitivityY * Time.deltaTime;
         verticalLookRotation = $$anonymous$$athf.Clamp(verticalLookRotation,-60,60);
         cameraTransform.localEulerAngles = Vector3.left * verticalLookRotation;
         
         // Calculate movement:
         float inputX = Input.GetAxisRaw("Horizontal");
         float inputY = Input.GetAxisRaw("Vertical");
         
         Vector3 moveDir = new Vector3(inputX,0, inputY).normalized;
         Vector3 target$$anonymous$$oveAmount = moveDir * walkSpeed;
         moveAmount = Vector3.SmoothDamp(moveAmount,target$$anonymous$$oveAmount,ref smooth$$anonymous$$oveVelocity,.15f);
         
         // Jump
         if (Input.GetButtonDown("Jump")) {
             if (grounded) {
                 rigidbody.AddForce(transform.up * jumpForce);
             }
         }
         
         // Grounded check
         Ray ray = new Ray(transform.position, -transform.up);
         RaycastHit hit;
         
         if (Physics.Raycast(ray, out hit, 1 + .1f, grounded$$anonymous$$ask)) {
             grounded = true;
         }
         else {
             grounded = false;
         }
         
     }
     
     void FixedUpdate() {
         // Apply movement to rigidbody
         Vector3 local$$anonymous$$ove = transform.TransformDirection(moveAmount) * Time.fixedDeltaTime;
         rigidbody.$$anonymous$$ovePosition(rigidbody.position + local$$anonymous$$ove);
     }
 }
Show more comments

1 Reply

  • Sort: 
avatar image
0
Best Answer

Answer by EmHuynh · Feb 27, 2016 at 09:23 PM

Hello, @Vampyr_Engel.

This line in the script: UnityEngine.Component.Rigidbody.rigidbody; does not declare a variable with of type, Rigidbody.

I think you intended to type: UnityEngine.Component.Rigidbody rigidbody;. There is a space between UnityEngine.Component.Rigidbody and rigidbody instead of a dot. Either way, it is invalid, this is how we declare a Rigidbody variable:

 // System vars
 bool          grounded;
 Vector3       moveAmount;
 Vector3       smoothMoveVelocity;
 float         verticalLookRotation;
 Transform     cameraTransform;
 Rigidbody     rigidbody;            // Valid.
Comment
Add comment · 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

Follow this Question

Answers Answers and Comments

119 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 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 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 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 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 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 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 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 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 avatar image avatar image

Related Questions

storing multiple data types in a list 0 Answers

Can not access opencv webcam script for use in another script 1 Answer

C# How to convert a struct type list into a string? 1 Answer

C# Find specific object by getting one of its variables 0 Answers

struct and stepping? (quest line) 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