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 Satamanster · Jul 09, 2012 at 05:14 PM · instantiateprefabpositiontankself

How to instantiate in self position.

Ok guys, my first post here on this website. I know it's kind of a noob question but, either i'm not looking from what is in front of my eyes, or.. i don't know.

So, i want to instantiate a prefab in the same position of a trigger when i enter it.

And i have this:

 var firePrefab: Transform;
 
 function OnTriggerEnter (other : Collider)
 {
  Instantiate(firePrefab, gameObject.position);
 }


So i presumed that if i attached the script to my object it would instantiate it where in the same position of my gameObject to where's the script is attached. Tommorow this will become a onCollisionEnter so that the script can be attached to a bullet and where the bullet hits, it destroys itself and instantiate my prefab, wich goes for 5 seconds and then disappeas, well that i know how to do with destroy and waitforSeconds commands. Can you solve this for me please? Thanks.

P.S. - Oh, and since i'm a noob with unity, keep it simple and stupid please. :D

P.S._2 - No need for raycasts here, the bullet is a rigid body since, well, is not a bullet, more like a missile to be shoot from a tank. :D Cheers. ;)

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 whydoidoit · Jul 09, 2012 at 05:16 PM

use #pragma strict at the top of your files and you will see that gameObject.position doesn't exist! You need to be using transform.position...

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 Satamanster · Jul 09, 2012 at 05:35 PM 0
Share

I already tried that:

Look, here's what i have now:

pragma strict

var firePrefab: Transform;

function OnTriggerEnter (other : Collider) { Instantiate(firePrefab, gameObject.transform.position); }

I tried with just transform.position and gameObject.transform.position and nothing works.

But I'm still getting this error. BCE0023: No appropriate version of 'UnityEngine.Object.Instantiate' for the argument list '(UnityEngine.Transform, UnityEngine.Vector3)' was found.

Shouldn't the gameObject.transform.position returns a vector3 by itself? What i'm i doing wrong?

avatar image whydoidoit · Jul 09, 2012 at 05:37 PM 0
Share

When you specify a position you also need to specify a rotation. Pass Quaternion.identity as the third parameter.

avatar image Satamanster · Jul 09, 2012 at 06:04 PM 0
Share

Thanks... You are my saver. :D i actually tought rotation was a optional and if i didn't put anything ther it automatically would assume the Quaternion.identity vector. :\ Weird. Well, thanks a lot, i've just been intro unity scripting and program$$anonymous$$g for the first time like, two monts ago and i still have a long way to go. Thanks!!!

avatar image whydoidoit · Jul 09, 2012 at 06:06 PM 0
Share

Hey no problem :) Just mark it as answered and I'm a happy man! (Click the tick under my answer).

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

How to follow multiple clones positions of an instantiate prefab having a velocity ? 1 Answer

Prefab instantiating problem 1 Answer

Wrong particle and prefab spawn position 1 Answer

Instantiating an Object doesn't use the given position. 1 Answer

Changing position of instantiated prefab from empty gameobject which is the location of the prefab when instantiating. 0 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