Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 KingCrizzo · Sep 10, 2012 at 12:11 AM · c#vector3vectordeclare

Declaring a Vector3 variable in C#

Can a Vector3 be a variable? I thought so, but I can't seem to find the correct syntax. How do I make this work?

 for (float i = 0 ; i < blockX; i++)
 {
 Vector3 rowX = (i,0,0); //error on this line
 Rigidbody instance = Instantiate (block,rowX, 0 );    
 }

This gives me the error: error CS1026: Unexpected symbol `,', expecting `)'

I have also tried skipping the declaration and just putting:

 Rigidbody instance = Instantiate (block,Vector3(i,0,0),0);

That gives me more errors though.

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
9
Best Answer

Answer by Jessespike · Sep 10, 2012 at 12:41 AM

Vector3 isn't a variable, it's a struct. You need create it instead of just assigning it, you were missing "new Vector3"

 for (float i = 0 ; i < blockX; i++)
 {
 Vector3 rowX = new Vector3 (i,0,0); //error on this line
 Rigidbody instance = Instantiate (block,rowX, 0 );  
 }
Comment
Add comment · Show 5 · 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 KingCrizzo · Sep 10, 2012 at 01:20 AM 0
Share

Thank you.

avatar image nishants · Jun 15, 2013 at 04:06 PM 0
Share

could you tell me how to do the same in JS

avatar image KingCrizzo · Jun 15, 2013 at 04:49 PM 0
Share

var name = Vector3(x,y,z);

avatar image nishants · Jun 15, 2013 at 04:50 PM 0
Share

Thank You.

avatar image SoldierofYHVH · Apr 11, 2018 at 05:56 AM 0
Share

Vector 3 is a Struct, eh? If this is the case, and you're supposed to call the constructor method of that Struct with the 'new' keyword on the right side of the equal sign, what is the purpose of writing this:

Vector3 relativePosition = target position -transform.position;

transform.rotation = Quaternion.LookRotation(relativePosition);

I know what and why that code works, but that "Vector 3 Struct" sure as hell looks kind of like a variable declaration to me!!!

There is no use of the 'new' keyword, and Vector 3 appears only on the left side of the equal sign. So you're saying,then, that 'relativePosition' is not a variable, but a Struct? Are you or are you are not storing a reference to that Vector 3 in a variable? Please elaborate...

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

12 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

Related Questions

Multiple Cars not working 1 Answer

Rigidody.velocity = Direction * speed; How to get direction? 1 Answer

Calculate the distance between an object and my player 1 Answer

Distribute terrain in zones 3 Answers

Given a vector, how do i generate a random perpendicular vector? 5 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