Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 xToxicInferno · Feb 16, 2010 at 04:18 AM · instantiatetransform

Instanitate Object with predefined script transforms

I know of no other way to word this question, then how i have. When instantiate a object, i want it to instantiate with it's scripts, and to have the Transforms i set in the script to be already set. By this, i mean i want to be able to spawn a enemy who, as soon as spawning, will know his target is the player. So any help would be appreciated.

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

Answer by Ashkan_gc · Feb 16, 2010 at 05:06 AM

simply create a GameObject and add all scripts that you want to it and set all values to what you want. then create a prefab in menu assets/create/prefab. drag your gameObject to the prefab and delete the gameObject. now use this prefab for instantiation. in the script that you want to instantiate the enamy define a variable like

var enamy:GameObject;

in the inspector drag the prefab to this variable in the GameObject that has this script attached. then use the Instantiate method to spawn the enamy where you want. if the initial position should be defined in code you ca do that in Awake or Start functions.

Comment
Add comment · Show 4 · 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 xToxicInferno · Feb 16, 2010 at 05:27 AM 0
Share

So you are saying i should define them as GameObject rather then Transform?

avatar image Ashkan_gc · Feb 16, 2010 at 10:02 AM 0
Share

you can use the second argument of instantiate to tell where to create the objet and also you can set the position in code of Start function. you can only set scripts of gameObjects and transforms don't have scripts becausee they are components themselves. use prefabs! they are great reusable components and help you when you want to change all instances of an object.

avatar image xToxicInferno · Feb 16, 2010 at 08:40 PM 0
Share

I already use prefabs. The code i use now is: var target : Transform; I was wondering if you mean to change it from Transform to GameObject.

avatar image Ashkan_gc · Feb 17, 2010 at 03:51 AM 0
Share

there is no difference because all gameObjects has transforms and you can not drag any transform that is not a gameObject. the difference comes in when you use another component type that is not available in all gameObjects. for example you might use WheelCollider or Rigidbody in the inspector to force yourself and other users to drag a gameObject that has a WheelCollider attached.

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

Rotating a certain axis offsets the other ones? 1 Answer

How to instantiate prefab over the text one letter at a time? OR how to get transform of letters in a text 0 Answers

How to Instantiate prefab as child? (Java) 1 Answer

Setting parent of instantiated object fails (Error: setting parent of prefab is disabled...) 1 Answer

Random Object spawning with transforms 2D 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