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 parkershaw · Apr 11, 2018 at 11:47 PM · scripting problemcollider

Box collider that triggers camera change

I'm trying to make a simple 3D game where you shoot an instantiated object (sphere) towards an end object and when it hits the end object, the camera changes to another one in the same scene, simulating a level change. I'm not sure if there's an easier way to change to another level, but i'm trying to keep it as simple as possible. Do I need to add a box collider to the end goal that makes it so when the instantiated ball hits it the camera is switched?

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by bennett_apps · Apr 11, 2018 at 11:56 PM

Lots of ways to move the camera. Yes, you could use a trigger that moves the Camera when you hit the object in front. Is the next goal directly in front every time? If so, you could just add a certain number of units on one axis to the camera every time OnTriggerEnter () is called. Like, say the first goal is at (10, 0, 0) and the second is at (20, 0, 0) and so on, the code would look like:

 void OnTriggerEnter () {
     transform.position += new Vector3 (10, 0, 0);
 }

You could also just switch scenes...

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

Answer by DuckGreatness · Apr 12, 2018 at 12:35 AM

You can have multiple cameras in your scene set where you want and switch between them. Yes I would have a collider on both objects and one of them should be a rigidbody. You can use the void OnCollisionEnter (Collision col) function attached to one of the game objects to trigger the camera switch. If you have 2 cameras, you can put a script on one (in this example the one that is not the main camera) like the following to switch on impact.

 private Camera _cMainCamera;

  void Start () {
     _cMainCamera = GameObject.Find("Main Camera").GetComponentInChildren<Camera>();
     GetComponent<Camera>().enabled = false;
 _cMainCamera.enabled = true;
     }

 OnCollisionEnter (Collision col){
 if (col.gameObject.tag == "Target"){
 _cMainCamera.enabled = true;
 GetComponent<Camera>().enabled = false;
 }
 }


Loading another scene can be very easy. Add using UnityEngine.SceneManagement; to your script and then use SceneManager.LoadScene ("NameOfYourScene"); Here is an example.

 using UnityEngine;
 using System.Collections;
 using UnityEngine.SceneManagement;
 
 public class LoadGame : MonoBehaviour {
     
     public void BeginAdventure (){
         SceneManager.LoadScene ("WorldMapIntro");
     }
 }


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

152 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

Related Questions

Change Material depending on Collider position? 2 Answers

Why when i move the player object through the door the ontriggerenter/exit event are not fire ? 2 Answers

How to change between scripts on trigger? 2 Answers

FPS all of a sudden gets stuck in floor??? 0 Answers

Connect 2 gameobjects to interact with them simultaneously? 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