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 Psudoz · Aug 18, 2013 at 07:58 PM · javascriptbeginners

Question about Unity_Scripting_Tutorial.pdf

In this unity tutorial http://www.ntua.gr/best/ac12/Unity_Scripting_Tutorial.pdf

it has this code

 var newObject : Transform;
 
 function Update () {
 if (Input.GetButtonDown("Fire1")) {
 Instantiate(newObject, transform.position, transform.rotation);
 }
 }

The part what I dont understand is the variable and where it says "transform.position transform.rotation." what does the transform mean after the variable and wouldn't you have to put newObject.transform.position?

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

Answer by aldonaletto · Aug 18, 2013 at 08:23 PM

The instruction:

 var newObject: Transform;

defines a public variable called newObject whose type is Transform. In Unity, this variable appears in the Inspector as a field named New Object (the Inspector creates a label based on the variable name), and you must assign to it an object from the Project view (a prefab). The instruction Instantiate creates a clone of this object at/with the position/rotation specified. In this case, transform.position is the position of the object that has this script, and transform.rotation is its rotation. In other words, when the button "Fire1" is pressed, a clone of the object defined in newObject is created at the same position and with the same rotation of the owner of this script.

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 Psudoz · Aug 18, 2013 at 08:41 PM 0
Share

very helpful. thank you.

avatar image
0

Answer by Nexonity · Aug 18, 2013 at 08:08 PM

transform.position and transform.rotation means the current position and rotation of the gameobject that the script is attached to.

Comment
Add comment · Show 10 · 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 Psudoz · Aug 18, 2013 at 08:41 PM 0
Share

If you have multiple game objects attached how do you specify which one?

avatar image Nexonity · Aug 18, 2013 at 08:50 PM 0
Share

I think you are mixing var newObject : Transform; with transform.position. The newObject : Tranform has nothing to do with transform.position. For example if you create a new variable like this: "var blah : Transform;" and then you change "tranform.position" with "blah.position" It will spawn at the position where the gameobject you assigned to "var blah : Transform"

avatar image Nexonity · Aug 18, 2013 at 08:52 PM 0
Share
 var newObject : Transform;
 var anotherObject : Transform;
 var blah : Transform;
  
 function Update () {
 if (Input.GetButtonDown("Fire1")) {
 Instantiate(newObject, blah.position, blah.rotation);
 Instantiate(anotherObject, blah.position, blah.rotation);
 }
 }
 
avatar image Psudoz · Aug 18, 2013 at 09:01 PM 0
Share

I don't think I understand.. so, like this?

 var Ob : Transform;
     var obtwo : Transform;
     
     function Update () {
     if (Input.GetButtonDown("Fire1")) {
     Instantiate(Ob, Ob.position, Ob.rotation)
     Instantiate(obtwo, obtwo.position, obtwo.rotation)
     }
     }
 
avatar image Nexonity · Aug 18, 2013 at 09:04 PM 0
Share

Take a look here: http://docs.unity3d.com/Documentation/ScriptReference/Object.Instantiate.html

Show more comments

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

17 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

Related Questions

Character Movement component 2 Answers

How to make a pirate ship game? 1 Answer

UI color issue 1 Answer

Is Unity Basic Allow to publish application on App Store? 1 Answer

Make an Educational Game using unity3d 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