Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 Roshel0836 · Mar 12, 2017 at 07:50 PM · scenebuttonsplane

3d object like PLANE act as clickable button?

May someone teach or guide me how to make a 3d object like plane as an clickable button that redirect me to the other scene?

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
1

Answer by jacksonbarnes · Aug 13, 2018 at 09:26 PM

Hi here is a simple script to make an object act like a button with a OnClick event. Just attach this script to a 3d object you would like to make a button. Cheers

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.Events;
 
 public class WebsiteButton : MonoBehaviour {
 
     public GameObject definedButton;
     public UnityEvent OnClick = new UnityEvent();
 
     // Use this for initialization
     void Start () {
         definedButton = this.gameObject;
     }
     
     // Update is called once per frame
     void Update () {
         var ray = Camera.main.ScreenPointToRay(Input.mousePosition);
         RaycastHit Hit;
         
         if (Input.GetMouseButtonDown(0))
         {
             if (Physics.Raycast(ray, out Hit) && Hit.collider.gameObject == gameObject)
             {
                 Debug.Log("Button Clicked");
                 OnClick.Invoke();
             }
         }    
     }
 }
Comment
Add comment · Show 1 · 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 nopharbm · Feb 26, 2019 at 08:46 AM 0
Share

Thank you so much for that script!

avatar image
0

Answer by Suley · Mar 14, 2017 at 09:36 AM

Hi,

you can find a few Posts about this:

Here and another one here

You have two Options. One is to use OnMouseDown or you could use Raycast to "hit" the 3d Object, but dont forget to put a collider on the 3d Object. You can see further details on those two links, which are provided.

Comment
Add comment · Show 3 · 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 Roshel0836 · Mar 14, 2017 at 10:49 AM 0
Share

Can this be apply in android mobile platform?

avatar image Matt1000 Roshel0836 · Mar 14, 2017 at 11:22 AM 0
Share

I'm pretty sure you can, specially On$$anonymous$$oueDown ().

avatar image Matt1000 · Mar 14, 2017 at 11:24 AM 0
Share

Actually, i think unity's On$$anonymous$$ouseDown funcion casts a ray to hit the object so there is little reason to create the ray. Unless you want more funcionalilty...

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

Objects can't be seen in scene view and appear again (In editor mode, not running) 0 Answers

Is it possible to get terrain tools on imported terrrain ? 1 Answer

How to add touchscreen controls to this script? 0 Answers

(CLOSED) Plane Failing to Render When Camera is Switched Until Scene is Reloaded?! 0 Answers

Can't Change Scenes When Built 4 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