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 HTH_jjpprogrammer · Sep 11, 2010 at 09:47 PM · variablevaluetype

What is typing a variable? Is it assigning the value?

In this tutorial it talks about assigning a type to a variable. Is this assigning the value of the variable? If not what is it for?

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

3 Replies

· Add your reply
  • Sort: 
avatar image
4

Answer by Terry.du · Sep 12, 2010 at 01:30 AM

No, it's not assigning the value.

Basically, when you declare a variable and specify the type, you're telling the Unity compiler what the variable can hold.

In the tutorial, Will created a variable named thePrefab and said this variable can only store a GameObject in it.

You'll also notice he didn't assign a value, a GameObject, in the script. He actually assigned a GameObject using the Inspector when he dragged the BouncyBox prefab, which is a GameObject, into the thePrefab variable. In the Inspector, Unity displays the thePrefab variable as The Prefab.

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
2

Answer by · Sep 14, 2010 at 12:25 AM

Answering jjpprogrammer's answer (which is actually a question in itself).

I can't access the tutorial from here, but I assume it's doing this:

var thePrefab : GameObject;

function Start () { var instance = Instantiate(thePrefab, transform.position, transform.rotation); }

The reason they're doing that is so you can access the instance of thePrefab that has been instantiated. If you want to change the position (or any property of that object), you can't access it by using 'thePrefab.position' (for example), because it's a link to a prefab, and not an actual GameObject.

For example:

function Update ()
{
   thePrefab.position.y += 1; // this would not work
   instance.position.y += 1;  // this would work
}

Check out the script reference for Object.Instantiate() for more information.

As I've commented above, you've actually asked a separate question inside an answer. Please keep questions as questions and answers as answers, as it helps to keep UnityAnswers easier to search/read for everyone.

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
0

Answer by HTH_jjpprogrammer · Sep 13, 2010 at 09:39 PM

Thanks! I have one more question. I think you might have answered this in your last answer but I am not sure . Why does he set the var instance to instantiate? I would think that assigning the instantiate to a variable would only set it to the variables value, not run it? Why not just say:

var thePrefab : GameObject;

function Start () {

Instantiate(thePrefab, transform.position, transform.rotation);

}

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 · Sep 14, 2010 at 12:20 AM 0
Share

This should be posted as a separate question.

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

No one has followed this question yet.

Related Questions

Expression denotes a 'type' 2 Answers

HELP!!! Expression denotes a `type', where a `variable', `value' or `method group' was expected 1 Answer

Get Value/String From GUIText 3 Answers

Checking if variable is nullable type? 3 Answers

How to keep variable value 3 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