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 ninjaboynaru · Jul 17, 2012 at 05:44 PM · varget component

Script to recive varible from toher script and do something with it

I would like to know hot to access a variable from another script. Also, is it possible to take a variable in another script and assign it to a variable in the current script, like if I had a variable named (health = 50) and I wanted to set this variable to another variable in my script named health1. So that if (health1) changes so dose (health)

EX. Would the following script work, are there any problems with it.

var health1 = gameObject.Find(Player1).GetComponent(health script).health

function Update () {

}

function OnCollisionEnter(Collided : Collision){

if(Collided.gameObject.name == "Wall")

health-=1;

{

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 Julien-Lynge · Jul 17, 2012 at 07:37 PM

@ninjaboynaru,

Your post comes across as you stating what you want done and demanding that someone here do it for you. I'm not sure if this was your intention, but that's now how UnityAnswers works. We're glad to help you, but we're not going to write your game for you. If that's what you're looking for, you can certainly hire someone on the forums.

That being said, people are absolutely right to point you to the Unity API and documentation. If you don't understand the Unity API, the first thing to do is to learn a bit about it before you try programming a complex script. If you don't understand the documentation within the reference pages, you may want to take a step back and invest some time in learning to program in JS or C#. There are many, many tutorials out there that walk you through simple programming, introduce variables and data structures, and will give you everything you need to know. When you've done that, then you should be able to follow the Unity GUI scripting guide (http://docs.unity3d.com/Documentation/Components/GUIScriptingGuide.html) and examples.

Good luck to you!

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 Julien-Lynge · Jul 17, 2012 at 07:41 PM 0
Share

BTW, I presume this is the API link that you looked at. If not, this is definitely what you're looking for:

http://docs.unity3d.com/Documentation/ScriptReference/index.Accessing_Other_Game_Objects.html

And just in case I'm way off base and you're a good programmer but just confused by Unity-specific syntax, there are quite a few good video tutorials out there that can help you. Try 3DBuzz, for instance:

http://www.3dbuzz.com/vbforum/sv_home.php

Click on Unity, and then Unity Fundamentals.

avatar image ninjaboynaru · Jul 18, 2012 at 07:13 PM 0
Share

Sorry if you thought I wanted you to write the script for me. I would just like to know how to access a variable from another script. I don't want anyone to write my script for me, that would not help me at all. What I would like is for someone to tell me how to use the (Get Component) function to get a variable.

avatar image ninjaboynaru · Jul 18, 2012 at 07:16 PM 0
Share

I have read the API on dot syntax but what I don't understand is after I get the script how do I get the variable in the script I want to use. And I am also confused about how I get a game object then get a script in that object and then access a variable in that script.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

set a var to a function in another script 2 Answers

custom variable type? 1 Answer

Changing a script value 1 Answer

How to Link Scripts Correctly? 1 Answer

On var enter 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