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
1
Question by tomowale · May 24, 2015 at 02:53 PM · tutorial

Tutorial Problems

I'm going through the Space Shooter tutorial on the Unity site to prepare to make my own game. As I was proceeding to run the game I kept getting this error "Assets/Scripts/PlayerController.cs(18,17): error CS1922: A field or property UnityEngine.Vector3' cannot be initialized with a collection object initializer because type UnityEngine.Vector3' does not implement System.Collections.IEnumerable' interface" Here is the code.using UnityEngine; using System.Collections;

public class PlayerController : MonoBehaviour { public float speed; public float xMin , xMax, zMin, zMax;

 void FixedUpdate ()
 {
     float moveHorizontal = Input.GetAxis ("Horizontal");
     float moveVertical = Input.GetAxis ("Vertical");


 Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
 GetComponent<Rigidbody>().velocity = movement * speed;
     GetComponent<Rigidbody>().position = new Vector3
     
     {
     Mathf.Clamp( Rigidbody.position.x, xMin,xMax),
         0.0f,
         Mathf.Clamp( Rigidbody.position.z, zMin, zMax)
     };
           
 }

}`

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 maccabbe · May 24, 2015 at 03:04 PM 1
Share

Use parenthesis when creating new objects like on line 7. On line 11/15 you are accidentally using curley brackets.

avatar image tomowale · May 24, 2015 at 04:32 PM 0
Share

I used () but Unity popped up a bunch of errors. I substituted line 11 with () and line 15 with () as well but got multiple errors. So what exactly do you mean?

avatar image Lo0NuhtiK · May 24, 2015 at 05:32 PM 0
Share

When you get errors, double click the top error and fix it, save the file, compile it again, and keep working your way down the list like that until the other errors are resolved.

1 Reply

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

Answer by Lo0NuhtiK · May 24, 2015 at 05:30 PM

     public float speed; public float xMin , xMax, zMin, zMax;

 //cache for <Rigidbody>
 Rigidbody rb ;

 void Start()
 {
     //cache our Rigidbody
     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
     //bad brackets you had here... {} != ()
     (
         Mathf.Clamp( rb.position.x, xMin,xMax),
         0.0f,
         Mathf.Clamp( rb.position.z, zMin, zMax)
     );
     
 }
Comment
Add comment · Show 3 · 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 tomowale · May 24, 2015 at 06:01 PM 0
Share
 (
         $$anonymous$$athf.Clamp (Rigidbody.position.x, x$$anonymous$$in, x$$anonymous$$ax),
             0.0f,
             $$anonymous$$athf.Clamp (Rigidbody.position.z, z$$anonymous$$in, z$$anonymous$$ax)
         );
     
     }          
avatar image tomowale · May 24, 2015 at 06:02 PM 0
Share

It seems to have worked for the most part but I get a parsing error on line 30 ( line below curly bracket) even though there is nothing there. Oh and yes I tried to add 2 more curl brackets.

avatar image tomowale · May 24, 2015 at 06:33 PM 1
Share

FIXED! I sat there and figured it out , pretty proud of myself .lol. But on the real thanks for helping me out with the previous error.

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

Common way to make a GameTutorial? 1 Answer

2D Game example 2 Answers

Best way to make a bullet hell shooter in Unity? 1 Answer

Roll-A-Ball Problem 2 Answers

Need Help in adding UI text in Unity 4.5 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