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 /
  • Help Room /
avatar image
0
Question by LeoSaurusRex · Apr 07, 2016 at 03:33 PM · index

accesing multiple objects that share the same script from another script

hello, i realize that there are other "similar" questions out there, but none of them are useful for me, or maybe they are but my limited understanding of c# gets on the way :p. now, I made a trap door on the ground that slides off once its "touch count" is depleted. it stays that way until the player dies (I'm not actually resetting the scene, just moving the player back to spawn). I'm using a game manager that handles timer, amount of coins gathered etc. this is also where I'm calling the "death" function (to keep track of the amount of deaths). i tried adding a public gameobject (on the game manager script) to quote the trapdoor, reset it's "touch count" and position, and it works flawlessly... so long as there's only one of them. now, how would you recommend doing this? resetting multiple objects (which I've tagged "reset") from the game manager???

 //this is the (relevant) script from the game manager
 public Trap_Platform_Controller resets;
 public bool hasPlatforms = true;
 
 public void addDeath()
     {
         deathCount += 1;
         if (hasPlatforms == true) {
             resets.touches = 2;
             resets.transform.position = resets.spawn;
         }
     }
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 Ali-hatem · Apr 07, 2016 at 04:41 PM 0
Share
 GameObject [] obj;
 Trap_Platform_Controller resets;
 public bool hasPlatforms = true;
  public void addDeath()
      {
       deathCount += 1;
          if (hasPlatforms == true) 
           {
              obj = GameObject.FindGameObjectsWithTag ("reset");
                for (int i = 0; i < obj.Length; i++)
                 {
                  resets= obj [i].GetComponent<Trap_Platform_Controller>();
                  resets.touches = 2;
                  resets.transform.position = resets.spawn; // how this line work !
                 }
           }
      }

resets is a reference for Trap_Platform_Controller script not transform so explane .

0 Replies

· Add your reply
  • Sort: 

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Index out of range on ray declaration 1 Answer

Creating Mesh - Vertices out of boundries 0 Answers

How can I change the colour of individual characters in a text string 2 Answers

IndexOutOfRangeException: Array index is out of range. GameManager.initializeCards () (at Assets/Scripts/GameManager.cs:41) GameManager.Update () (at Assets/Scripts/GameManager.cs:23) 0 Answers

How to go about making a word guessing game based on picture 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