• 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 /
  • Help Room /
avatar image
0
Question by True_Lucifer · Feb 14, 2016 at 05:16 AM · instantiaterelative positionvector 3

Instantiated GameObjects move in vector 3 in relation to where the game object spawns them

what im trying to do is when i have my working sphere script instantiate these game objects that instead of them only staying in the set vector 3 that they have to move the vector 3 in a relative position to where i have the game object that insatntiates them at.

this is my current code its in c#

public class BombSelfAction : MonoBehaviour {

 public float Timer = 5;
  
 // Use this for initialization
 void Start () 
 {
     tempPos = transform.position;
 }
 
 // Update is called once per frame
 void Update () {
     
     //enabling this script
     //----------------------------------------------------------------------------------------------------------------------------------

     gameObject.GetComponent<BombSelfAction>().enabled = true;
     
     // makes the timer for the script
     //----------------------------------------------------------------------------------------------------------------------------------

     Timer -= Time.deltaTime;
     
     GameVariables.BombArmed = false;


     if (Timer <= 0)
     {
         GameVariables.BombArmed = true;
         {
             //Destroy(gameObject);
             
          // declaring the five pauls needed   

                  
         GameObject prefab = Resources.Load("paul") as GameObject;
         GameObject paul = Instantiate (prefab) as GameObject;

             
         GameObject prefaba = Resources.Load("paul") as GameObject;
         GameObject pauli = Instantiate (prefaba) as GameObject;
     

            
     GameObject prefabb = Resources.Load("paul") as GameObject;
     GameObject pauly = Instantiate(prefabb) as GameObject;
                
       
     GameObject prefabl = Resources.Load("paul") as GameObject;
     GameObject paulie = Instantiate(prefabl) as GameObject;
                
     
      GameObject prefabla = Resources.Load("paul") as GameObject;
      GameObject pauliee = Instantiate(prefabla) as GameObject;
        
       GameObject prefablb = Resources.Load("paul") as GameObject;
       GameObject pauliy = Instantiate(prefablb) as GameObject;

             // spawns at where the sphere was 
             //--------------------------------------------
                     
            paul.transform.localPosition = transform.position;

             // spawns left of sphere
             //--------------------------------------------
         pauli.transform.localPosition = new Vector3(4, 1, -1);
         // or 
         //--------------------------------------------
         //pauli.transform.position = Vector3.right * 4 + Vector3.up + Vector3.back;


             // spawns right of sphere
             //--------------------------------------------
             
            //pauly.transform.localPosition = new Vector3(4, 1, 0);
    

         //spawns in front of sphere
         //--------------------------------------------
         pauliy.transform.localPosition = new Vector3(3, 1, 0);

             //spawns behind sphere
             //--------------------------------------------
             pauliee.transform.localPosition = new Vector3(5, 1, 0);



     //destroys each paul after 2 seconds
     //--------------------------------------------

          Destroy(paul, 2);
          Destroy(gameObject);
      
          Destroy(pauly, 2);
      Destroy(gameObject);
  
     Destroy(pauli, 2);
     estroy(gameObject);
  
      Destroy(paulie, 2);
      Destroy(gameObject);
  
      Destroy(pauliy, 2);
      Destroy(gameObject);
  
     Destroy(pauliee, 2);
         Destroy(gameObject);


         }
     }
 
 }

}

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

Answer by gorbit99 · Feb 14, 2016 at 02:29 PM

Get the starting pos of the objects and just add them together with the pos you want them to move to.

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

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

45 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 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

Spawning limited GameObjects at a specific position not working 1 Answer

spawn object every 10 score points 1 Answer

How do I instantiate an object that does not exist in my scene? 0 Answers

How to instantiate a game object every time when space key is pressed 2 Answers

Instantiate an object until edges of floor 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