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 /
avatar image
0
Question by yesiamzack · Apr 04, 2014 at 10:01 PM · clickdisableenable

How to Activate Script in another Object?

Pretty simple, hopefully, but I'm a complete disaster with scripting. I'm using a Lerp script that moves an object from Point A to Point B which is great. However, I'd like to enable that movement, via another script, only when another object has been clicked. I've attempted various solutions with no luck.

Here's the movement script (called Lerp2)

 // Transforms to act as start and end markers for the journey.
     var startMarker: Transform;
     var endMarker: Transform;
 
 

 // Movement speed in units/sec.
     var speed = 1.0;
     
     // Time when the movement started.
     private var startTime: float;
     
     // Total distance between the markers.
     private var journeyLength: float;
     
     var target : Transform;
     var smooth = 5.0;
     
     function Start() {
     
         // Keep a note of the time the movement started.
         startTime = Time.time;
         
         // Calculate the journey length.
         journeyLength = Vector3.Distance(startMarker.position, endMarker.position);
         
     }
     
     // Follows the target position like with a spring
     function Update () {
     
 // Distance moved = time * speed.
         var distCovered = (Time.time - startTime) * speed;
         
         // Fraction of journey completed = current distance divided by total distance.
         var fracJourney = distCovered / journeyLength;
         
         // Set our position as a fraction of the distance between the markers.
         transform.position = Vector3.Lerp(startMarker.position, endMarker.position, fracJourney);
     }

I'm assuming there's an easy way using OnMouseOver and GetMouseButtonDown to have a line of code that activates this script from another object.

Thanks in advance :)

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
0

Answer by djfatsteve2 · Apr 04, 2014 at 10:21 PM

to connect scripts...

(at top of file)

 var scriptVar : exactNameOfScriptYouWishToAccess;


to call a function on that script from the one you included (as seen above)

 scriptVar.otherScriptFunction();

 




Remember: You'll have to connect the scripts in the inspector by dragging the object that contains the specified script on it.

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

22 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

Related Questions

Another Java to C# Conversion Question!! 1 Answer

Disabling/Enabling Different Character Controllers. 1 Answer

disable/enable script js 2 Answers

Disable & Re-enable Script 1 Answer

enable disable variable of a script from another script 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