Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 Stedlerd · Jan 23 at 12:01 AM · instantiatecloneclonespathfollowing

Making clones of a GameObject but then the original gets destroyed

So, I'm trying to make a SpaceInvaders-type game, and I made a gameObject, called "Enemy1", which has a script that tells him to follow a specific path;

I then made a spawner, that makes (trough Instantiate command) some "Enemy1" clones. This spawner, makes a clone every 1 second, for 5 seconds, so it should spawn 4-5 clones, with the original "Enemy1" gameObject, all of them creating a queue in this path.

Everything works just fine, the only problem is that, if while the clones are spawning, I try to "kill" the original gameObject, the other clones stop spawning, because they have no more reference to the original "Enemy1".

The problem is that these enemies move because the path script is inside them so, if I try to make just a reference for the clones that is stationary and not in the scene so it can't being killed, all the clones will spawn like him, and will not move.

How can I make a reference for the clones that cannot being killed, but still tell them to move following the path?

Thanks, I'm really struggling with this one.

Here is the spawner script:

 using UnityEngine;
 
 public class EnemySpawner : MonoBehaviour
 {
     private float currentTimeToSpawn;
     public float timeToSpawn;
     public float maxTimeToSpawn = 5;
     public Transform pointA;
     public GameObject enemy;
 
    
 
     // Update is called once per frame
     void Update()
     {
         if(maxTimeToSpawn > 0)
         {
 
         
                 if(currentTimeToSpawn > 0)
                 {
                     currentTimeToSpawn -= Time.deltaTime;
                 }
                 else
                 {
                     SpawnObject();
                     currentTimeToSpawn = timeToSpawn;
                     maxTimeToSpawn--;
                 }
             
         }
         
     }
         void SpawnObject()
         {
             Instantiate(enemy, pointA.position, Quaternion.identity);
         }
  }

aaand I'm not sure it's useful, but here's the path script that should be in every enemy.

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class Interpolation : MonoBehaviour
 {
     [SerializeField] private Transform pointA;
     [SerializeField] private Transform pointB;
     [SerializeField] private Transform pointC;
     [SerializeField] private Transform pointD;
     [SerializeField] private Transform pointAB;
     [SerializeField] private Transform pointBC;
     [SerializeField] private Transform pointCD;
     [SerializeField] private Transform pointAB_BC;
     [SerializeField] private Transform pointBC_CD;
     [SerializeField] private Transform pointABCD;
 
     private float interpolateAmount;
    
     
     
     // Update is called once per frame
     
 
      private void Update()
     {                        
         interpolateAmount = (interpolateAmount + Time.deltaTime/6);
         /*pointAB.position = Vector3.Lerp(pointA.position, pointB.position, interpolateAmount);
         pointBC.position = Vector3.Lerp(pointB.position, pointC.position, interpolateAmount);
         pointCD.position = Vector3.Lerp(pointC.position, pointD.position, interpolateAmount);
         pointAB_BC.position = Vector3.Lerp(pointAB.position, pointBC.position, interpolateAmount);
         pointBC_CD.position = Vector3.Lerp(pointBC.position, pointCD.position, interpolateAmount);
         pointABCD.position = Vector3.Lerp(pointAB_BC.position, pointBC_CD.position, interpolateAmount); */
          pointABCD.position = CubicLerp(pointA.position, pointB.position, pointC.position, pointD.position, interpolateAmount);
     }
     private Vector3 QuadraticLerp(Vector3 a, Vector3 b, Vector3 c, float t)
     {
         Vector3 ab = Vector3.Lerp(a, b, t);
         Vector3 bc = Vector3.Lerp(b, c, t);
 
         return Vector3.Lerp(ab, bc, interpolateAmount);
     }
 
     private Vector3 CubicLerp(Vector3 a, Vector3 b, Vector3 c, Vector3 d, float t)
     {
         Vector3 ab_bc = QuadraticLerp(a, b, c, t);
         Vector3 bc_cd = QuadraticLerp(b, c, d, t);
 
         return Vector3.Lerp(ab_bc, bc_cd, interpolateAmount);
         
         
     }
 
     
 
         
     
 }
 
 
 



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

0 Replies

· Add your reply
  • Sort: 

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

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

Instantiate problem, spawning too many clones, then cloning the clones! help! 0 Answers

[2D] Instantiate() duplicates former instances 1 Answer

Unable to set position of instantiated prefab 1 Answer

I need help about Basic Basketball Game 0 Answers

I need help destroying a clone on function. 1 Answer


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