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 /
avatar image
0
Question by MixdMAT95 · Mar 01, 2020 at 02:33 AM · scripting problemcollisionvariablesscene-loading

How do I get an object to send a value to a manager script using an ontriggerenter?

I have an object with a script on it called SafeZone. I want this script to return true when entered by the player tagged game object. so I did: alt text

Then on my ManagerScript I want to check the Boolean from SafeZone and load a new scene when its true.

I have a reference to the SafeZone script on my ManagerScript by making the gameobject a prefab and setting it in the editor via the inspector.

I set up my levels by giving them a curLevel and nextLevel name and set them to the name needed to access the next level in the build. It works when on the zone itself. SceneManager.Loadscene(nextScene.name);

alt text

nothing works. I made sure CheckSafe(); is called from update method I also added a debug line to the function and it doesn't get output to the console window either. However, the boolean on the game object will still toggle when the player object enters it. It just isn't sending that value to the GameManager script. At the moment I kept it on the SafeZone gameObject and it loads the next scene just fine, but I don't know if this is the best way to do this. Can anyone tell me what i'm doing wrong?

The reason I want to keep it all on the GameManager is I also have a public int for lives on the script as well, and a deathzone. I want to reset the level, not reload which is another beast I'm working on implementing, and decrease the lives value by 1. Same deal with the script an OTE that checks for the player on a separate game object. That when entered should return the boolean entered as true, and decrease the lives value by one or lives--; and reset the level function Reset(); so something like CheckDeath(){ if (DeathZone.entered == true) { lives--; Reset();}}

untitled.png (15.4 kB)
untitled2.png (10.7 kB)
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 MixdMAT95 · Mar 01, 2020 at 02:36 AM 0
Share

Sorry about the mess I gave this spaces and everything but It got bunched together when submitted. I don't have the screen grabs at the moment or I would add them. This is all just from memory of the issue. I've been doing a lot of research and dabbling in this area to make this function work, but I can't seem to get the scripts to send information updates to each other when two separate game object's collision happens.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Zentiu · Mar 02, 2020 at 01:16 PM

If you gamemanager handles the loading then this is what i usually do:

I assume there should always be 1 game manager.

 public class GameManager : Monobehaviour
 {
     public static GameManager manager;
     public bool isInSafeZone = false;
 
     public Start ()
     {
         manager = this;
     }

     public void LoadScene (int nextScene)
     {
         SceneManager.LoadScene (nextScene);
     }

 }

And then in your script that checks if the player enters the safeZone:

 Public void OnTriggerEnter (collision other)
 {
 
     if(other.gameObject.compareTag ("Player") == true)
     {
         GameManager.manager.isInSafeZone = true;
         GameManager.manager.LoadScene(1);
     }
 
 }


Ofcourse you can let the method LoadScene activate somewhere else instead of when the player enters te trigger. But this should work.

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

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

Collision without movement!?? 2 Answers

My Raycast acts like it's hitting something when it isn't 0 Answers

Load a scene from AssetBundle 0 Answers

2D Platformer - Picking Up Items & Storing Them C# 0 Answers

How do you deactivate a static script until a certain key is pressed? 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