Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by DJgray3D · Aug 21, 2013 at 11:28 AM · gameobjectactivate

Script for buttons referencing different Game Objects

Hi, I've got some box collider buttons on a panel as part of an augmented reality console. The buttons are triggered by rays. I need to write a script that references buttons 1 through 7, to activate/deactivate other game objects that are acting as video screens. This is the latest of my my poor attempts, and I'll be honest, every script I try is drag and dropped onto the camera, the buttons, the video planes, and a separate scripts game object. I appreciate this is simple stuff, which is all the more surprising I can't find an previous answer on here. Ta in advance. R

 #pragma strict
 
 private var ray: Ray;
 private var hit : RaycastHit;
 private var vid2 : GameObject;
 private var vid5 : GameObject;
 
     function Start () {
         vid2 = GameObject.Find("Bottom right/Videos Panel/Vid2");
         vid5 = GameObject.Find("Bottom right/Videos Panel/Vid5");
         vid2.gameObject.SetActive(false);
         vid5.gameObject.SetActive(false);
     }
 
 function Update () {
 
     if(Input.GetMouseButtonDown(0)){
         ray = Camera.main.ScreenPointToRay(Input.mousePosition);
         if(Physics.Raycast(ray, hit)){
             if(hit.transform.name == "VidBt2"){
                 vid2.gameObject.SetActive(true);
                 vid5.gameObject.SetActive(false);
 }
             if(hit.transform.name == "VidBt5"){
                 vid2.gameObject.SetActive(false);
                 vid5.gameObject.SetActive(true);
 
 
 }
 }
 }
 }
 
Comment
Add comment · Show 3
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 DJgray3D · Aug 21, 2013 at 12:48 PM 0
Share

$$anonymous$$ I'm getting closer but it's still not quite there, surely it's common to activate a separate hierarchy object / object's animation via a button and script it?

 #pragma strict
 
 private var ray: Ray;
 private var hit : RaycastHit;
 private var vid2 : GameObject;
 private var vid5 : GameObject;
 
     function Start () {
         vid2 = GameObject.Find("Bottom right/Videos Panel/Vid2");
         vid5 = GameObject.Find("Bottom right/Videos Panel/Vid5");
         vid2.SetActive(false);
         vid5.SetActive(false);
     }
 
     function Update () {
 
     if(Input.Get$$anonymous$$ouseButtonDown(0)){
         ray = Camera.main.ScreenPointToRay(Input.mousePosition);
         if(Physics.Raycast(ray, hit)){
             if(hit.transform.name == "VidBt2"){
                 vid2.SetActive(true);
                 vid5.SetActive(false);
 }
             if(hit.transform.name == "VidBt5"){
                 vid2.SetActive(false);
                 vid5.SetActive(true);
 
 
             }
         }
     }
 }
 
avatar image Joyrider · Aug 21, 2013 at 08:53 PM 0
Share

And it's not working as it is? What is happening? Do you get errors?

avatar image hollym16 · Aug 22, 2013 at 01:04 PM 0
Share

I think I had the script in place multiple times and it was fighting against itself. It's on a separate scripts object now and works well. Now I have to do the same thing but access a script component in the hierarchy in order to turn THAT on and off. Should be easy in comparison.

0 Replies

· Add your reply
  • Sort: 

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

18 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

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

How to activate a script from another script at runtime 1 Answer

Object won't reactivate or activate with button press. 2 Answers

Changing gameobject assigned to a variable on input.getkey. 2 Answers

Combine objects instantiated at runtime 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