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 /
  • 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.

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

Highlighting all clones instead of the one the mouse is over. 0 Answers

Exponential Instantiation 0 Answers

Only allowing one instance of prefab created by button press & destroying prefab on collision? 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