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 devonzamfir · Mar 22, 2018 at 12:52 PM · gamescene-switchingscenes

I can't figure it out.

I have done everything I can to create a SceneChanging script. There are no error, I set it as Trigger, I gave the player a Collider and it just doesn't work. I would love is somebody would try my game out and tell me what the error is. A link to it is here: http://www.mediafire.com/file/m76vm36vg967kne/FPS_openworld.1.unity.zip

PS! Important: The teleportation block is the Gold block on top of the hill. The player is a FPSController named "Player". To get up there either solve the puzzle, or place the Player up on the mountain. Thank you very much!

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 donutLaserDev · Mar 22, 2018 at 12:56 PM 0
Share

Scene without the actual assets is broken. You should upload the whole project.

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Legend_Bacon · Mar 22, 2018 at 01:10 PM

Hello there,

Could you give us a little more information please? Like post your code, tell us what you are trying to do, describe which components are on your objects, etc... We can't help you if your question is that vague.

Other than that, you also need to upload the actual project (or a build) if you want us to test it. A scene file can't work without your scripts, assets, settings, etc...


UPDATE:

Site wouldn't let me post a new comment, so here it is:

I didn't make a prefab per say, but this will help you regardless. Just make a new script and call it "OnCollisionLoadScene". Then, you can place it on your cube.

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.SceneManagement;
 
 [RequireComponent(typeof(Collider))]
 public class OnCollisionLoadScene : MonoBehaviour
 {
     [SerializeField] private string sceneToLoad = "";
 
     //Check Collision against all tags in this list
     [SerializeField] private List<string> list_tagsToWatchFor = new List<string>();
 
     // Enable OnCollisionEnter
     [SerializeField] private bool checkForCollision = false;
     // Enable OnTriggerEnter
     [SerializeField] private bool checkForTrigger = false;
     //Enable DistanceCheck
     [SerializeField] private bool checkForDistance = false;
     [SerializeField] private float distanceToCheck = 0.0f; // Radius to check
     [SerializeField] private float distanceCheckRefreshEvery = 0.0f; // Check for distance every X seconds
 
     private void Start()
     {
         if (checkForDistance)
             StartCoroutine(CheckForDistanceCoroutine());
     }
 
     private void OnCollisionEnter(Collision collision)
     {
         if (!checkForCollision)
             return;
 
         if (list_tagsToWatchFor.Contains(collision.gameObject.tag))
         {
             Debug.Log("COLLISION: LOAD SCENE");
             SceneManager.LoadScene(sceneToLoad);
         }
     }
 
     private void OnTriggerEnter(Collider collision)
     {
         if (!checkForTrigger)
             return;
 
         if (list_tagsToWatchFor.Contains(collision.gameObject.tag))
         {
             Debug.Log("TRIGGER: LOAD SCENE");
             SceneManager.LoadScene(sceneToLoad);
         }
     }
 
     private IEnumerator CheckForDistanceCoroutine()
     {
         while (checkForDistance)
         {
             List<GameObject> objectsToCheck = new List<GameObject>();
             foreach (string item in list_tagsToWatchFor)
                 objectsToCheck.AddRange(GameObject.FindGameObjectsWithTag(item));
 
             foreach (GameObject item in objectsToCheck)
             {
                 if (Vector3.Distance(transform.position, item.transform.position) <= distanceToCheck)
                 {
                     Debug.Log("DISTANCE: LOAD SCENE");
                     SceneManager.LoadScene(sceneToLoad);
                     break;
                 }
             }
 
             yield return new WaitForSeconds(distanceCheckRefreshEvery);
         }
         yield return null;
     }
 
     //Purely for distance vizualisation in the scene
 #if UNITY_EDITOR
     private void OnDrawGizmos()
     {
         Gizmos.color = new Color(0.65f, 0.0f, 0.0f, 0.25f);
         Gizmos.DrawSphere(transform.position, distanceToCheck);
     }
 #endif
 }
 


• The collision works IF your player has a Collider NOT trigger and a rigidbody.

• The TRIGGER collision works IF your player has a Collider trigger and a rigidbody.

• The distance check works continuously as long as you have it enabled.

Don't forget to fill the fields you need in the inspector before using it!


Hope that helps!

Cheers,

~LegendBacon

Comment
Add comment · Show 4 · 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 devonzamfir · Mar 22, 2018 at 01:19 PM 0
Share

Hello! The whole file compressed is still quite big (Around 700$$anonymous$$B). Do you know if there is any easier way to do this? Let me explain what I am trying to do. I am trying to get it so that when my FPSController, with a Rigidbody and Collider, (who is tagged "Player) when he touches a Golden Cube with a box collider with isTrigger checked, changes to the next scene. $$anonymous$$y script is:

 using UnityEngine.Scene$$anonymous$$anagement;
 using UnityEngine;
 
 public class NewBehaviourScript : $$anonymous$$onoBehaviour
 {     
     void OnCollisionEnter(Collision collision)
     {
         if (collision.gameObject.tag == "Player")
         {
             Scene$$anonymous$$anager.LoadScene ("Pklvl2");
         }
     }
 }


Sorry for being so vague.

EDIT: Also I am uploading my Project to files.fm under this link: https://files.fm/u/jq4ghxr3 . Once it is done I will reply again incase you still want to see the Project file! :)

avatar image Legend_Bacon devonzamfir · Mar 22, 2018 at 01:30 PM 0
Share

Ah, I see. Thank you for uploading the script.

Unfortunately, a Trigger will not raise the OnCollisionEnter event when colliding with a Collider.

You have two solutions here:

  1. Change your cube to NOT be a trigger. Then everything works as you have it.

  2. Add a second Collider to your player, and mark it as Trigger. Then, change your method to:

      void OnTriggerEnter(Collider collision)
         {
             if (collision.gameObject.tag == "Player")
             {
                 Debug.Log("COLLISION");
             }
         }
    
    
    

Hope that helps!

Cheers,

~LegendBacon

avatar image devonzamfir Legend_Bacon · Mar 22, 2018 at 01:57 PM 0
Share

Hello there! Sorry about taking so long to respond. It still doesn't work using both methods. I know this may be a bit much to ask, but do you think you could create a prefab of a scene changing item. I would really appreciate it. You don't have to do it any time soon, but if you have some free time could you please try it? Thank you so much!

Show more comments

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

109 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

Related Questions

Scene loads in editor not in build 0 Answers

how do i Disable and Enable buttons? 2 Answers

One Location Game (with Scenes Loaded and Disabled) 0 Answers

Multiple rooms (spheres) with different entrances/exits 0 Answers

Quit application before relaunching to specific scene 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