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 /
avatar image
1
Question by solopolo · Jun 20, 2017 at 11:11 PM · cs1061

Space Shooter Tutorial Error CS1061

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class PlayerController : MonoBehaviour {
 
     public float speed;
     public float xMin, xMax, zMin, zMax;
 
     private Rigidbody rb;
 
     void Start()
     {
         rb = GetComponent<Rigidbody>();
     }
 
     void FixedUpdate()
     {
         float moveHorizontal = Input.GetAxis("Horizontal");
         float moveVertical = Input.GetAxis("Vertical");
 
         Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
         rb.velocity = movement * speed;
 
         rb.position = new Vector3(Mathf.Clamp(rigidbody.position.x, xMin, xMax), 0.0f, Mathf.Clamp(rigidbody.position.x, zMin, zMax));
 
     }
 }

I'm following the space shooter tutorial on the unity learn page, using Unity 5, but the tutorial was made on Unity 4, sooo obviously there are differences (also considering the tutorial was made on a Mac and I'm using Windows).

After updating my script, I returned to Unity and got two errors on the same line:

"Assets/Scripts/PlayerController.cs(25,57): error CS1061: Type UnityEngine.Component' does not contain a definition for position' and no extension method position' of type UnityEngine.Component' could be found. Are you missing an assembly reference?"

"Assets/Scripts/PlayerController.cs(25,110): error CS1061: Type UnityEngine.Component' does not contain a definition for position' and no extension method position' of type UnityEngine.Component' could be found. Are you missing an assembly reference?"

the only difference between the two errors is the second number in the parentheses. I know the first number tells you which line the error is referring to, but I have no idea what the second number is for.

What are the errors telling me to do/how would I do it? What's the fix here? I looked at the update guide for the videos but I can't see any fixes for it.

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
1

Answer by eskivor · Jun 20, 2017 at 11:36 PM

TL;DR : at lines 25 and 26 replace rigidbody by rb


In Unity 5, you cannot use anymore directly rigidbody as a shortcut to reference the component Rigidbody, using rigidbody was equivalent to use GetComponent<Rigidbody>(). Now using the short version rigidbody is impossible (to avoid users to use too much the GetComponent function (which can be consuming) when it's unnecessary, because they ignored they were using GetComponent functions). You have to use instead GetComponent<Rigidbody>() here to get the Rigidbody component attached to the gameObject. But you are already using the variable rb to get the Rigidbody component, so you can simply use rb here.

You can also report the bug of the tutorial to Unity

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 solopolo · Jun 21, 2017 at 12:30 AM 0
Share

Huh. I completely passed over those rbs. Guess I need to look a bit more closely. Thanks for the help. :D

One more thing. After fixing the error, I went back into Unity and tested it, and now it's doing really strange things. When I try to move upwards, the ship moves up a bit and stops two units, then when I release the up key, it goes back down to its original position. When I press down it does the same thing in the other direction. When I press right, it moves towards the top right limit then moves right 2 units, then goes left 2 units when I release the right key. When I press left, it goes to the bottom left limit, then 2 units left, and 2 units right when I release.

Here's my updated script (boundaries are x$$anonymous$$in = -6, x$$anonymous$$ax = 6, z$$anonymous$$in = -4, z$$anonymous$$ax = 8) : using System.Collections; using System.Collections.Generic; using UnityEngine;

 [System.Serializable]
 public class Boundary
 {
     public float x$$anonymous$$in, x$$anonymous$$ax, z$$anonymous$$in, z$$anonymous$$ax;
 }
 
 public class PlayerController : $$anonymous$$onoBehaviour {
 
     public float speed;
     public Boundary boundary;
 
     private Rigidbody rb;
 
     void Start()
     {
         rb = GetComponent<Rigidbody>();
     }
 
     void FixedUpdate()
     {
         float moveHorizontal = Input.GetAxis("Horizontal");
         float moveVertical = Input.GetAxis("Vertical");
 
         Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
         rb.velocity = movement * speed;
 
         rb.position = new Vector3($$anonymous$$athf.Clamp(rb.position.x, boundary.x$$anonymous$$in, boundary.x$$anonymous$$ax), 0.0f, $$anonymous$$athf.Clamp(rb.position.x, boundary.z$$anonymous$$in, boundary.z$$anonymous$$ax));
 
     }
 }
 

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

66 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

Related Questions

Compiling error: AndroidJavaClass and AndroidJavaObject problems 0 Answers

float to string c# unity script Android csharp 2 Answers

Trouble wth Error CS1061 2 Answers

Targetting script errors 1 Answer

INTERNAL COMPILER ERROR 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