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 csavenables · May 21, 2012 at 02:11 PM · gameobjectarraysonmousedown

GameObject Array

Hello,

I would to walk up to an object in my scene (first person controller), click on a sphere for arguments sake and a new object/cube will appear in it's place, then if this is clicked another new object/cylinder will appear. Finally I would like to click on the cylinder and it will loop around back to the sphere, it's key this cycle continues. I have been trying to use Array's for this, I have successfully created a material array (from pieces of acquired script) but I have not been as successful for Object Arrays.

I hope this is clear, this is what I have in the way of script to begin with:

var arr : GameObject[];

private var index : int;

function OnMouseUp ()

Your help will be greatly appreciated :)

Comment
Add comment · Show 1
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 Berenger · May 21, 2012 at 02:42 PM 0
Share

Could you please delete this one ?

1 Reply

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

Answer by Berenger · May 21, 2012 at 02:46 PM

In that case, the script inplementing OnMouseUp would be attached to the sphere and the cylinder. You should add a variable called something like next. When the message OnMouseUp is received, you can deactive this object and active next.

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 csavenables · May 21, 2012 at 03:30 PM 0
Share

Thank you for the speedy reply, I am still pretty new to all of this (3weeks) and scripting is not my strong point. There appears to be many ways to do what I need to do, some people have suggested using the Instantiate command, others suggest using an Index, I am still unsure which method to use. Or if to use both!

From your comment Berenger I have gathered that I need to input a new variable, but what script do I need to deactivate/active said object and how can I repeat said process?

avatar image Berenger · May 21, 2012 at 03:42 PM 0
Share

For such a simple task, you don't need to care about performance. Instantiate is just as good as activate / deactivate then. Anyway, there is always a lot of solution for each problems. There is a lot of parameters to consider to choose the good one, such as performance, how much times it takes to implement, the coherence with the rest, and finally the programmer's taste ^^ (non-exhaustive list).

Anyhow, the toggle between the name and the icon of a gameObject in the inspector is the variable active, accessible from code. All the components are disabled when the gameobject holding them is deactivated. Here is what I had in $$anonymous$$d :

var next : GameObject; // The cylinder for the sphere, the sphere for the cylinder.

function On$$anonymous$$ouseUp() { gameObject.active = false; next.active = true; }

avatar image csavenables · May 22, 2012 at 09:45 AM 0
Share

Perfect! Thank you very much, you are a life saver!

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

Select every GameObject in GameObject Array 2 Answers

Need help with assigning game objects to variable 2 Answers

How can I get every other GameObject except for the one I'm using? 1 Answer

Three Spots For Three Random Objects 1 Answer

odd error in c# script when working with arrays 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