• 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 dank_memes420 · May 24, 2016 at 01:47 AM · instantiate prefabclones

Clone of clones

When I instantiate my missile prefab, the game creates a copy from the clones that already exist, so when I fire once I have 1 clone, I fire again and I have 3 because the one of the clones if from a clone. The more I fire the more clones of clones are made making the game crash. How would I set it so the missiles only spawn at the original location and not from clones.

 using UnityEngine;
 using System.Collections;
 
 public class rightSmallMissile : MonoBehaviour {
     GameObject prefab1;
     public AudioSource bigMisileExp;
     public AudioClip impact;
     public ParticleSystem exp;
     public ParticleSystem aloha;
     public float speed = 200.0f;
     // Use this for initialization
     void Start () {
         prefab1 = Resources.Load("rightSmallMissile") as GameObject;
         exp = GetComponent<ParticleSystem>();
     }
     
     // Update is called once per frame
     void Update ()
     {
         if (Input.GetMouseButtonDown(1))
         {
              GameObject rightSmallMissile = Instantiate(prefab1, transform.position, transform.rotation) as GameObject;
             rightSmallMissile.transform.position = transform.position + Camera.main.transform.forward * 2;
             Rigidbody rb = rightSmallMissile.GetComponent<Rigidbody>();
             rb.AddForce(transform.forward * 260, ForceMode.Impulse);
              Destroy(rightSmallMissile, 4);
         }
     }
     void OnCollisionEnter(Collision collision)
     {
         if (collision.gameObject.name != "rightSmallMissile")
         {
             speed = 0.0f;
             if (speed >= 0.0f)
             {
                 speed = 0.0f;
             }
             aloha.Play();
             transform.position = new Vector3(transform.position.x, transform.position.y, transform.position.z);
             if (aloha.isPlaying == true)
             {
                 if (!bigMisileExp.isPlaying)
                 {
                     bigMisileExp.PlayOneShot(impact, 1);
 
                 }
                 Destroy(gameObject, 1.6f);
             }
             Destroy(gameObject, 0.6f);
         }
     }
 }
 
Comment
Add comment · Show 1
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 Nazirzadeh · May 24, 2016 at 12:23 PM 0
Share

I can not read your code!

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by dank_memes420 · Jun 02, 2016 at 02:32 AM

Never mind I figured out what the problem was. i was instantiating it from the prefab, i created a public GameObject and used that instead. it fixed it up, thanks anyways guys.

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

Answer by ZenardX2 · Jul 04, 2020 at 02:47 PM

it still does the same ..

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

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

Related Questions

How can I have spawned gameObjects be treated as individuals by other scripts? 0 Answers

Changing material dose not change the appearance of the game object 0 Answers

C# How to call a function in only one of many prefab clones? 2 Answers

Instantiating UI Prefab - Error: Setting parent of a transform which resides in a prefab is disabled. What's wrong with my code? 1 Answer

I wrote a script for instanciating a prefab after ontriggerexit() function, but it is instanciated to with a variation in position.y from the empty gameobject i placed - where it should be instanciated 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