• 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 Imagineum · Aug 30, 2014 at 08:18 AM · movementchild object

Reactivated Child doesn't move.

I`m working on a game where some enemies are inactive at begining and while player make progression they are reactivated. All addition enemies are childs of empty GameObject called EnemyActivator2…8 because I couldn't ractivate them.

Here's a code that disable my additional enemy on start and reactivate it when player hits 200 points. This script is attached to Empty GameObject that is parrent. Only Enemy GameObject has Rigidbody2D.

    using UnityEngine;
     using System.Collections;
     
     public class EnemyActivatorController2 : MonoBehaviour {
     
         // Use this for initialization
         void Start () {
             GameObject ActiveEnemy2 = GameObject.Find ("EnemyActivator2");
             foreach (Transform child in ActiveEnemy2.transform) {
                             child.gameObject.SetActive (false);
                     }
     
     
         }
         
         // Update is called once per frame
         void Update () {
             if (PlayerController.Points == 200) {
                 GameObject ActiveEnemy2 = GameObject.Find ("EnemyActivator2");
                 foreach (Transform child in ActiveEnemy2.transform) {
                     child.gameObject.SetActive (true);
                 } 
             }
         
         }
     }
 

It working but my additional enemy spawn and doesn't move anymore.

Here is enemy script:

 using UnityEngine;
     using System.Collections;
     
     public class EnemyController2 : MonoBehaviour {
     
         public float speed = -1;
         private Transform spawnPoint;
     
         // Use this for initialization
         void Start () {
             spawnPoint = GameObject.Find("SpawnPoint").transform;
             rigidbody2D.velocity = new Vector2 (speed, 0);
     
     
     
         }
         
         // Update is called once per frame
         void Update () {
         
         }
     
         void OnBecameInvisible()
         {
             if (Camera.main == null)
                             return;
     
             float yMax = Camera.main.orthographicSize - 0.5f;
             transform.position = new Vector3( spawnPoint.position.x,
                                              Random.Range (-yMax, yMax),
                                              transform.position.z );
         }
     
     }
 
 

Any idea how to make he move again? Enemies just wander from left to right or vice versa and when move out from the screen they will spawn again. Please help me :)

Comment
Add comment · Show 4
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 AngryBurritoCoder · Aug 30, 2014 at 11:40 AM 0
Share

what are you enemies supposed to do ? all I see if adding velocity to them and nothing else, they supposed to follow the player or something ?

avatar image _MGB_ · Aug 30, 2014 at 01:05 PM 0
Share

It may not be waking up... have you tried calling the 'WakeUp' method?

avatar image Kobting · Aug 30, 2014 at 01:14 PM 1
Share

I don't know how your points work, but if the players points aren't exactly 200 points then all the enemy will be deactivated again. (This is assu$$anonymous$$g that the points don't stay constant until you do something)

avatar image Imagineum · Aug 30, 2014 at 08:18 PM 0
Share

Child is active but dont move. Same with bormal GameObject. When I disabled it in play mode and enabled again Enemy didnt move when appear.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Imagineum · Aug 31, 2014 at 04:18 PM

Problem Solved. Thanks Kobting! + for You mate!

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

25 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

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Making a bubble level (not a game but work tool) 1 Answer

How to Have Projectile Reset to Initial Position Relative to Parent 1 Answer

Move/Rotate Kinematic (2D) Child with MovePosition/MoveRotation Doesn't Work 0 Answers

Need help with char movement. 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