Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
avatar image
1
Question by MegaDriver · Jun 28, 2015 at 12:10 PM · gameobjectcolliderparticlesystemreferencingactivation

Game Object not activating when commanded by function in another script.

Hi, this is my first time asking anything in here and really, my first time doing anything semi-serious in Unity.

I ran into a bit of a problem that has me stuck:

I'm making a game that takes the Roll a Ball tutorial's basis and expands on it as a practice of what I can do, so most of the code is mostly a copy of the tutorial.

The think that has kept me stuck is that I have a particle system attached to an Empty Game Object as a child. The following code is supposed to deactivate the Empty Game Object (plus the particle sys) and reenable it after the itemCount (from the script called PlayerController) reaches 4.

 public class LevelExit_Portal_Controller : MonoBehaviour {

 public GameObject portal;
     public GameObject player;
     
     void Start () 
     {
         portal.gameObject.SetActive (false);
     }
 
     void Update () 
     {
 
         PlayerController playerController = player.GetComponent<PlayerController> ();
         if (playerController.itemCount == 4) {
             OnPortalActivation ();
         }
 
     }
     void OnTriggerEnter (Collider other)
     {
 
 
         if (other.gameObject.CompareTag ("Player")) {
             Application.Quit ();
 
         }
     }
     void OnPortalActivation ()
     {
         portal.SetActive (true);
     }

 }

All code is valid according to the Editor and MonoDevelop correctly detects the script reference. The code snippet that activates the win message that contains itemCount also runs fine. The problem is that the Empty Game Object is not activating, therefore not allowing it to be used to change level with collision detection and neither it activates the Particle System child.

What am I doing wrong? Am I missing something? Should I put all this code on the same script as the Player Game Object (as in, put it in PlayerController instead of its own script?)

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 Buzz Hsu · Jun 28, 2015 at 03:55 PM 2
Share

What object did you put this script on? Once the gameobject is turned off by SetActive(false), all its script stop functioning. $$anonymous$$aybe you can try put this script on the parent empty object, but set the portal field to be the child (particle system) itself.

avatar image MegaDriver · Jun 28, 2015 at 07:21 PM 0
Share

The script is on the Parent Empty Game Object the ParticleSys is attached to as seen here:

alt text

alt text

avatar image fuego_see_money · Jun 30, 2015 at 09:30 PM 0
Share

Are you sure that the player has IsTrigger checked in the inspector? And are you sure your player's item count is actually reaching 4?

avatar image MajorParts · Jun 30, 2015 at 10:46 PM 0
Share

buzz is right...you're object is levelexit_Portal and the portal is defined as that too, so you are deactivating the gameobject that has the script to reactivate it.

Put it all in a script on your player object, or a gamemanager empty object.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Locate a game object using rays 1 Answer

destroy gameobject when collider is fast enough? 2 Answers

How can i check if GO collided with collider starting with name (string) 1 Answer

How to get a List of references of instances in a static variable 1 Answer

how to make particles collide with particles c# 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