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 AlexRMSTITANIC · May 29, 2011 at 08:13 PM · gameobjectmenu

One GameObjects Script Activating Another GameObjects Script

Hello I'm very new to Unity and I will say it is an amazing engine. But for some time now, I've had this dilemma of witch I have no idea how to fix or do, and that's activating and GameObject to effect another. I have looked around and used codes like...

(For Java Scripts)

otherObject.GetComponent(NameOfScript).enabled = true;

But seem to get no were, if it is possible, could someone show me the right way to do these sorts of codes in a little script example.

My situation is this, this is on a main menu and there's is a button and a camera. Lets say when I click the button (named "NewGame"), it goes to a new scene, but before that, I want a little animation of the camera(Named "Maincamera") moving in. There's already a script attached to the camera(script named "cameramove") that when activated, plays the animation. How would the script for the button look like if it activates the camera script.

Cheers

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

1 Reply

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

Answer by Anxo · May 29, 2011 at 08:22 PM

well you first want to put everything in a varible, the way your going about it, may work like this

 var objectB : GameObject;
 var objectBScript;
 
 function Awake(){
    objectB = GameObject.FindWithTag("objectB");
 objectBScript = objectB.GetComponent(superscript);
 }
 function TurnOnScript(){
   objectBScript.enabled = true;
 }

Another way you could handle it would be to just use a boolean as a switch in object B so

on Object be

 var Off : boolean = true;
 function Update(){
 
 if (Off)
 return;
 //this line would not run till off is turn off.
 }
 function TurnOffOff(){
 Off = false;
 }

then in object A you would have a script like

 var objectB : GameObject;
 
 function Awake()
 {
 objectB = GameObject.FindWithTag("objectB");
 }
 function turnOffOFf(){
 objectB.BroadcastMessage("TurnOffOff");
 //sends a message to object B to run the turnoffoff function
 }
Comment
Add comment · Show 6 · 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 AlexRMSTITANIC · May 29, 2011 at 09:11 PM 0
Share

Thank you for the quick response, but still it does not want to work. I've done exactly what you said and copied them into my scripts, I renamed them to there proper names, set everything in the right order and tested, no luck. I even made a new scene and named everything like you did, but still, it was a no go. This is a really need thing for the type of game I'm making. I just have no other idea how I will do this.

Again though, thank you.

avatar image Anxo · May 31, 2011 at 03:47 PM 0
Share

are you sure your tagging the object and not just creating the tag? I use gameObject.Broadcast$$anonymous$$essage("function"); all the time.

avatar image Anxo · May 31, 2011 at 03:49 PM 0
Share

oh you also have to call turnOffOff, so like in Awake or how ever you want to trigger it, you need to call the function like

function Start(){ turnOffOff(); }

avatar image Anxo · May 31, 2011 at 03:49 PM 0
Share

link your code if you still dont get it

avatar image AlexRMSTITANIC · May 31, 2011 at 05:24 PM 0
Share

I think I'm starting to understand this more, the only one thing I'm a little curious about is the tags, you said "are you sure your tagging the object and not just creating the tag?", so would that mean i can only choose one of the 7 tags available?

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

2 People are following this question.

avatar image avatar image

Related Questions

static var for one object. 2 Answers

Change position of GameObject between unity3d and eclipse 0 Answers

How to change variables on a new gameobject's script 1 Answer

gameObject.GetComponent("Script").enabled = true not working 5 Answers

Basic scripting problem 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