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
0
Question by edrocks4u · Jun 22, 2012 at 06:47 PM · c#transformarrayvector3

Setting position of a transform?

Hello im trying to set the position of a transform i can do this with vectors but i want to use a transform because later i will need to get/set the rotation to.

What i did

 public Transform[] cameraPos = new Transform[10];
 public Vector3[] camPos = new Vector3[10];
 
 // Use this for initialization
 void Start () {

//this works

     camPos[0] = new Vector3(13.6f, -3.1f, 3.3f);

//this dosent work

     cameraPos[0].position = new Vector3(-1.4f, -3.1f, 3.3f);
 }



Also here is the error im gettting

 UnassignedReferenceException: The variable cameraPos of 'CameraPosition' has not been assigned.
 You probably need to assign the cameraPos variable of the CameraPosition script in the inspector.
 UnityEngine.Transform.set_position (Vector3 value)
 CameraPosition.Start () (at Assets/ModelViewer/CameraPosition.cs:16)
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

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by SarperS · Jun 22, 2012 at 07:40 PM

You are trying to give a value to a null array field. Assign the transform you want to position into the cameraPos array's 0th field in the inspector.

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

Answer by Wolfram · Jun 22, 2012 at 08:20 PM

Internally, Vector3 can be seen a struct, which essentially means you can directly use it, assign stuff to it, and it will never be null. This is, from a programmers perspective, not entirely accurate, but it helps for noticing the inherent difference between this kind of object, and the other category of objects:

Almost all other objects in Unity are classes. They work differenty, they can be arbitrarily complex, but most importantly, they don't work "just like that". You'll first have to create or assign an object to them. They are only references to objects. They can be null.

For example, this says "I am a vector, use me":

 Vector3 myVec;

But this is just "look, I can be an object, but you need to show me which one":

 GameObject myGameObject;
 Component myComponent;
 Transform myTransform;

For these objects, you first need to assign them something. You can do that in the inspector. Or for example create new ones:

 myGameObject=new GameObject("I am a new object");
 myComponent=myGameOBject.AddComponent<MeshRenderer>();
 myTransform=myGameObject.transform; // when creating a new GameObject, it will already have a transform
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

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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to change Vector3 if an objects rotation is a certain number? 1 Answer

How to apply in opposite direction to transform? 1 Answer

How to check if a vector 3 is in a vector 3 array c#. 1 Answer

C#: Change transform.position in code 1 Answer

get nearest game object 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