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 Razputin · Dec 11, 2014 at 01:23 AM · rotationinstantiatetransformposition

How to instantiate object at particular location

I have an object called "laucher" which instantiates "spears" every 4 seconds, the spears are supposed to go flying forwards from the launcher until they collide with a wall. however i'm having some problems understanding Instantiate.

 This Script is Attached to "Launcher"
 
 using UnityEngine;
 using System.Collections;
 
 public class Launcher : MonoBehaviour {
 
     public GameObject Spear;
     public float counter = 0;
 
     void Update () {
         if(counter <= 4)
         {
             counter += Time.deltaTime;
         }
         else{
         Instantiate(Spear, new Vector2(-24,0), Quaternion.identity);
         counter = 0;
         }
     }
 }

  1. How do I make the spear instantiate at the launcher itself?

  2. How do I properly Instantiate the spear, because right now they're instantiated as Spear(Clone).

I can't just use a set location because I have multiple "Launcher" firing "Spear" at different spots of the level.

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

Answer by ahmedbenlakhdhar · Dec 11, 2014 at 01:32 AM

  1. You can retrieve the current position of the game object containing the actual script by using transform.position.

  2. You are instantiating with the right way, you still can change the name of the created game object.

Try this:

 // Instantiate at transform.position
 GameObject newSpear = (GameObject)Instantiate(Spear, transform.position, Spear.transform.rotation);
 // Change the name
 newSpear.name = "Spear";
Comment
Add comment · Show 6 · 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 Razputin · Dec 11, 2014 at 01:38 AM 0
Share

The spears that are currently being instantiated are invisible for some reason

avatar image Razputin · Dec 11, 2014 at 01:44 AM 0
Share

Ohhh lol for some reason they were spawning in backwards, making them invisible because they're 2d

avatar image ahmedbenlakhdhar · Dec 11, 2014 at 01:47 AM 0
Share

Is the game object which you are using to instantiate (Spear) is visible?

avatar image Razputin · Dec 11, 2014 at 01:51 AM 0
Share

Spear is losing its prefab rotation upon instantiate for some reason. Should be 0,180,0 but it spawns in 0,0,0

avatar image ahmedbenlakhdhar · Dec 11, 2014 at 01:54 AM 0
Share

By using this Quaternion.identity you override the original rotation.

Use this ins$$anonymous$$d Spear.transform.rotation. I updated the answer.

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

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

Related Questions

Dropping an object behind player in respect to rotation,How to drop an object behind the player 1 Answer

transform position and rotation of instantiated object 1 Answer

"Object reference not set to an instance of an Object" 0 Answers

How to make Camera position Independent of its Rotation? 1 Answer

Object instantiate, Projectile problems 2 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