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
-3
Question by aiibee · Nov 19, 2012 at 08:55 PM · gamejava

Script in UNITY ???

I have some question on scripting in unity. I am learning and i hope some one can clear this out the way so i can keep learning more. at the moment how i am using my scripts is i simple write it, and attach it to my object.

is there another way to do this where I can control multiple objects in my scene with just one large code attached to (????)....

lets say i have a ball that has animations, and there will be triggers in my scene(Cube). the ball will animate passing trough it, once triggered it will start an other animation of an other object in the scene, or start a particle or even bring up text.

how about if i want to have a set resolution of my game, so the player has only one option when the build is created. I am pretty sure that i can't write my code and drop it. There needs to be a other way.

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
Best Answer

Answer by MibZ · Nov 19, 2012 at 11:48 PM

You DON'T need multiple scripts to control multiple objects. If you wanted to you could control an entire game through one script. (Minus all of the Unity under the hood of course, but that's already programmed for you.)

If you wanted to you could even have one object controlled by multiple scripts, just make sure you don't overcomplicate it and lose track of how things work.

If you only want to do simple changes to objects (move, rotate, scale, change texture in runtime, etc) you can use a GameObject reference. This can be done two ways, the Designer friendly way and the Programmer friendly way.

 //"Designer method"
 public GameObject sphereToMove;
 
 //Public variables can be seen and changed in the Inspector tab. To assign a GameObject as sphereToMove, drag the GameObject you want from your Hierarchy tab into the variable in the Inspector. 
 //This method is nice because it lets you very easily change which GameObject is effected by your script without having to change any code.
 
 
 
 //"Programmer method"
 public GameObject sphereToMove = GameObject.Find("Basketball");
 
 //I still used 'public' accessibility, but it can also be 'private'.
 //This method is nice for when you have a lot of objects in your scene, or for when you know that a script will only be used to effect one object. (For example, your Player script will only effect players, and if you are making a single player game you will only ever have one player.)

To use this to make your script effect more than one object, you need to create a GameObject variable for each individual object you want to move. If you have more than a handfull of them I would recommend reading up on Arrays and Lists.

If you want to effect more than one object in complicated ways (For example, you want to add 10 health to every enemy in your scene) you need to have a script reference. Script references can be made for any script, whether that is a script that comes with Unity (Like Spring Joints or Character Controllers) or a script that you have written yourself.

To declare a script reference, use the name of the script as the Type.

 //NOTE: Accessing a script requires one more step than finding a GameObject, you need to use the [GetComponent][3] function like so.
 
 public GunTurret turret = GameObject.Find("Turret").GetComponent<GunTurret>();


[3]: http://docs.unity3d.com/Documentation/ScriptReference/GameObject.GetComponent.html

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
avatar image
0

Answer by Cool Dave · Nov 19, 2012 at 11:09 PM

Don't know what you're asking but here is link to an answer for a question you might be asking.

http://answers.unity3d.com/questions/316035/very-simple-question.html

The second question...

Edit>Project Settings>Player>PC and Mac TAB>Display Resolution Dialog

It's in the only sensible place...the player settings.

Try to ask one question per post. And writing in proper English is preferred.

Hope this helps!

Dave

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 aiibee · Nov 20, 2012 at 01:43 PM 0
Share

thank you :)

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

12 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

Related Questions

how can i add a gun sound to this script? 0 Answers

My bullet wont move forward 1 Answer

Making an animation play when you press down 2 keys 1 Answer

i need some code suggestions 1 Answer

How do you script in Java? Anyone have some exaple codes I could use? 0 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