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
1
Question by tibewww · Feb 09, 2016 at 06:41 PM · changeclick objectsscene change

change scene on click of a 3d object

Hi All,

I'm using unity 5.3, I'm trying to change scene on click of a 3d object (cube) ( not a GUI Button).

I'm using this Javascript:

 #pragma strict
 
 function Start () {
 
 }
 
  function Update () {
          if(Input.GetMouseButton(0))
              SceneManager.LoadScene("number2");
      }

Without success, I'm having this error: BCE0005: Unknown identifier: 'SceneManager'.

I tried different code, and can't make this work . . . Any help would be amazing !

Thank you for your time

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 aditya · Apr 20, 2016 at 10:20 AM 1
Share

please make sure whether the name of your gameObject is cubone and not cubeone, i m saying this because Vagonn's script is correct .... plus Vagonn is not posting JavaScript code he is using C#, so copying and pasting his code in your Js file will not work, create a new c# file then paste his code

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Vagonn · Feb 09, 2016 at 07:17 PM

This will change scene all time when you click left mouse button. But you need change scene when clicking on Cube. Try this

EDIT: Create new C# script named SceneChange.cs

  using UnityEngine;
  using System.Collections;
  using UnityEngine.SceneManagement;
  
  public class SceneChange : MonoBehaviour {
  
      Ray ray;
      RaycastHit hit;
  
      void Update()
      {
          ray = Camera.main.ScreenPointToRay(Input.mousePosition);
          if (Physics.Raycast(ray, out hit) && Input.GetMouseButton(0))
          {
              if (hit.collider.name == "cubone") 
              {
                  SceneManager.LoadScene("scena2stanza");
              }
          }
      }
  }

Comment
Add comment · Show 13 · 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 Gianluca90 · Apr 19, 2016 at 02:49 PM 0
Share

Hello Vagonn, i've copied your java script, i've changed "your cube name" and "number2" with my name object and scene, i've put it in a cube but it doesn't work. What's wrong?alt text

cattura.png (32.5 kB)
avatar image Vagonn · Apr 19, 2016 at 04:08 PM 0
Share

Hello. It seems I made mistake in javascript. Try this C# code.

Create new C# script named SceneChange.cs

 using UnityEngine;
 using System.Collections;
 using UnityEngine.Scene$$anonymous$$anagement;
 
 public class SceneChange : $$anonymous$$onoBehaviour {
 
     Ray ray;
     RaycastHit hit;
 
     void Update()
     {
         ray = Camera.main.ScreenPointToRay(Input.mousePosition);
         if (Physics.Raycast(ray, out hit) && Input.Get$$anonymous$$ouseButton(0))
         {
             if (hit.collider.name == "cubone") 
             {
                 Scene$$anonymous$$anager.LoadScene("scena2stanza");
             }
         }
     }
 }



avatar image Gianluca90 Vagonn · Apr 20, 2016 at 08:00 AM 0
Share

It doesn't work. I would like to say i work with gear vr and the name of my ray script is raycaster. i found it here: http://www.samsung.com/us/samsungdeveloperconnection/developer-resources/gear-vr/apps-and-games/exercise-1-creating-a-unity-project.html I put raycaster and reticle into a camera. alt text

cattura.png (54.0 kB)
avatar image Vagonn Gianluca90 · Apr 20, 2016 at 08:57 AM 0
Share

I guess I don't understand what you needed

Show more comments
Show more comments
avatar image Gianluca90 Vagonn · Apr 21, 2016 at 02:17 PM 0
Share

sorry, with click i want say touch the touchpad.

avatar image Gianluca90 Vagonn · Apr 26, 2016 at 03:55 PM 0
Share

With mouse the script works. But when i try to change scene with the ray, it doesn't work...why?

avatar image Vagonn Gianluca90 · Apr 26, 2016 at 05:22 PM 0
Share

Try this

http://docs.unity3d.com/ScriptReference/Camera.ViewportPointToRay.html

avatar image meat5000 ♦ · Apr 20, 2016 at 11:03 AM 0
Share

If I am correct here, which someone might really need to check, your if statement presents too much processing compared to what it could.

If I am correct the arguments in the if statement are evaluated from left to right until one is false in which case it moves on.

With this in $$anonymous$$d, if you placed your $$anonymous$$ouse-Poll first and your Raycast second, in theory, the raycast will only be performed upon the mouse co$$anonymous$$g back true.

  • could be way off here and it might not work like that at all.*

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

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Scene Change on Player Collision 1 Answer

Scene change on collision script? 1 Answer

Material on/off 1 Answer

Why am I getting this error ? - The type `RandomMovement' already contains a definition for `ChangeRotation' 1 Answer

Transition from GameMaker to Unity 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